Created
July 22, 2018 19:58
-
-
Save shakyShane/9dbd83eadc2b996c1e24652501976a7a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * 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