-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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: 3.5.1
Search Terms: regression, mapped types, tuples
Code
type Model<TProps = any> = {
props: TProps;
};
type ExtractModelProps<TModel extends Model> = TModel extends Model<
infer TProps
>
? TProps
: never;
type Options<TType extends string = string, TModel extends Model = Model> = {
type: TType;
getModel: () => TModel;
};
type ExtractPropsListFromOptionsList<TOptionsList extends Options[]> = {
[P in keyof TOptionsList]: TOptionsList[P] extends Options
? ExtractModelProps<ReturnType<TOptionsList[P]["getModel"]>>
: never
};
// expected: [string, number]
type PropsList = ExtractPropsListFromOptionsList<[
{
type: 'foo',
getModel: () => {
props: string
}
},
{
type: 'bar',
getModel: () => {
props: number
}
}
]>;Expected behavior:
PropsList should be [string, number], no error emitted.
Actual behavior:
In 3.4.5, it works as expected.
In 3.5.1, it emits errors at ExtractModelProps<ReturnType<TOptionsList[P]["getModel"]>>:
Type 'ReturnType<TOptionsList[P]["getModel"]>' does not satisfy the constraint 'Model<any>'.
Type 'unknown' is not assignable to type 'Model<any>'.
Type 'ReturnType<TOptionsList[keyof TOptionsList]["getModel"]>' is not assignable to type 'Model<any>'.
Type 'unknown' is not assignable to type 'Model<any>'.
Type 'ReturnType<TOptionsList[string | number | symbol]["getModel"]>' is not assignable to type 'Model<any>'.
Type 'unknown' is not assignable to type 'Model<any>'.
Type 'ReturnType<TOptionsList[string]["getModel"]> | ReturnType<TOptionsList[number]["getModel"]> | ReturnType<TOptionsList[symbol]["getModel"]>' is not assignable to type 'Model<any>'.
Type 'ReturnType<TOptionsList[string]["getModel"]>' is not assignable to type 'Model<any>'.
Type 'unknown' is not assignable to type 'Model<any>'.ts(2344)
If I change TOptionsList[P] extends Options to P extends number, it won't emit errors. But the result of PropsList is [never, never].
Seems the version of Playground is not 3.5.1 for now.
Related Issues:
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