Skip to content

Instantly share code, notes, and snippets.

@shakyShane
Created July 22, 2018 19:58
Show Gist options
  • Select an option

  • Save shakyShane/9dbd83eadc2b996c1e24652501976a7a to your computer and use it in GitHub Desktop.

Select an option

Save shakyShane/9dbd83eadc2b996c1e24652501976a7a to your computer and use it in GitHub Desktop.
/**
* This is a mapped type I would maintain manually
*/
interface DefineTypes {
"jquery": JQueryStatic,
"underscore": Underscore
}
/**
* This is an example of the 'define' function from requirejs, where it would take
* an array of keys from DefineTypes and accept a callback that will receive
* the types as positional arguments
*/
function test<T extends keyof DefineTypes>(name: T[], cb: () => void) {
}
/**
* Here's what I want, the positional arguments (`$` and `_`) to be
* determined using mapped types above, with zero annotations
*/
test(["jquery", "underscore"], function($, _) {
// in here, `$` shown be known to be JQueryStatic
// in here, `_` shown be known to be Underscore
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment