GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Type instantiation for type level generic function · Issue #62524 · microsoft/TypeScript Open Labels Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScriptAn idea for TypeScript Description🔍 Search Termstype instantiation Related: #40542, #61133 and maybe #52035? Edit: Just found #55435 and #40179 ✅ Viability Checklist
⭐ Suggestion#47607 added support for instantiation expressions, but those do not apply at the type level. I understand it'd be ambiguous in some cases (#47607 (comment)), but in some cases there really isn't a reasonable workaround. 📃 Motivating ExampleI actually have a very similar case to the example provided in #40542 const provideBox = () => { const box = <T>(value: T) => ({value}); return box; }; type BoxMaker = ReturnType<typeof provideBox> // type BoxMaker = <T>(value: T) => { value: T; } type Box1<T> = ReturnType<BoxMaker<T>>; // Type 'BoxMaker' is not generic.(2315) const box = undefined as unknown as BoxMaker; type Box2<T> = ReturnType<typeof box<T>>; //type Box2<T> = { value: T; } Compiler Options{
"compilerOptions": {
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"strictPropertyInitialization": true,
"strictBindCallApply": true,
"noImplicitThis": true,
"noImplicitReturns": true,
"alwaysStrict": true,
"esModuleInterop": true,
"declaration": true,
"target": "ES2017",
"module": "ESNext",
"moduleResolution": "node"
}
}Playground Link: Provided 💻 Use Cases
In our case we have a more complex
I cannot extract and export a generic type for a return value of a generic function if I don't have direct reference to the function.
The only workaround I found is to use a dummy runtime value to apply the type, and use and instantiation expression on that dummy value (see Activity
MetadataMetadataAssigneesLabelsAwaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScriptAn idea for TypeScript TypeProjectsMilestoneRelationshipsDevelopmentIssue actions |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |