- Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issue
Milestone
Description
TypeScript Version: typescript@next, typescript@3.5.1
Search Terms:
generic index is not assignable
Code
interface SettingsTypes { audio: { volume: string; }; video: { resulution: string; } } interface Settings<Params extends { [K in keyof Params]?: string }> { config: Params; }; // Example 1 type ThisWorks = Settings<SettingsTypes['audio']>; // Example 2 type ThisDoesntWork<T extends keyof SettingsTypes> = Settings<SettingsTypes[T]>; // ERROR: // Type '{ volume: string; }' is not assignable to type '{ [K in keyof SettingsTypes[T]]?: string | undefined; }'. // oh, ok but then why this works? // Example 3 type ThisWorksAgain = Settings<{ volume: string; }>;
Expected behavior:
Generic should work the same if we pass an specific index of an interface (1), a generic index of an interface (2) or when we pass the type directly (3)
Actual behavior:
Typescript throws an error only for the construction Settings<SettingsTypes[T]>
.
Related Issues:
32017 and 31904
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issue