Skip to content

Instantly share code, notes, and snippets.

@tannerlinsley
Created August 9, 2022 03:25
Show Gist options
  • Save tannerlinsley/1011ebc06c89e9436e5e809734bc1608 to your computer and use it in GitHub Desktop.
Save tannerlinsley/1011ebc06c89e9436e5e809734bc1608 to your computer and use it in GitHub Desktop.

Revisions

  1. tannerlinsley created this gist Aug 9, 2022.
    38 changes: 38 additions & 0 deletions FrameworkGenerics.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@
    // my-core

    interface FrameworkGenerics<TData = unknown> {
    // Options: unknown
    }

    type GetFrameworkGeneric<
    U,
    TData = unknown,
    > = U extends keyof FrameworkGenerics<TData>
    ? FrameworkGenerics<TData>[U]
    : unknown

    export function getCoreOptions (opts: GetFrameworkGeneric<'Options'>) {
    return opts
    }

    // React Adapter

    declare module 'my-core' {
    interface FrameworkGenerics<TData = unknown> {
    Options: {
    react: true
    }
    }
    }



    // Vue Adapter

    declare module 'my-core' {
    interface FrameworkGenerics<TData = unknown> {
    Options: {
    vue: true
    }
    }
    }