You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Intersection with mapped type broken in function with generic in 4.1.2 #41655
Where the UpdateQuery definition in the mongodb types is defined as:
typeDotAndArrayNotation<AssignableType>={readonly[key: string]: AssignableType;};typeReadonlyPartial<TSchema>={readonly[keyinkeyofTSchema]?: TSchema[key];};exporttypeMatchKeysAndValues<TSchema>=ReadonlyPartial<TSchema>&DotAndArrayNotation<any>;exporttypeUpdateQuery<TSchema>={$set?: MatchKeysAndValues<TSchema>;// other fields here don't matter};
Expected behavior:
Code is valid.
Actual behavior:
Only the function testWithGeneric throws an error. But since MatchKeysAndValues is defined as an intersection between ReadonlyPartial<TSchema> and a mapped type of string keys with any values, it should be accepted.
Type '{ [x: string]: any; }' is not assignable to type 'MatchKeysAndValues<TSchema>'. Type '{ [x: string]: any; }' is not assignable to type 'ReadonlyPartial<TSchema>'.
Activity
avaly commentedon Nov 24, 2020
I suspect this might be related to or caused by #40778
RyanCavanaugh commentedon Dec 3, 2020
This is a correct error; a legal invocation of your generic function would create an unsound result:
You should add a type assertion here to indicate that you believe situations like this won't occur
typescript-bot commentedon Dec 6, 2020
This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes.