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
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>'.
TypeScript Version: 4.1.2 and 4.2.0-dev.20201123
Search Terms:
UpdateQuery
,Intersection
,Generic
Code
Where the
UpdateQuery
definition in themongodb
types is defined as:Expected behavior:
Code is valid.
Actual behavior:
Only the function
testWithGeneric
throws an error. But sinceMatchKeysAndValues
is defined as an intersection betweenReadonlyPartial<TSchema>
and a mapped type of string keys with any values, it should be accepted.This used to work in version 4.0.5.
Playground Link: https://www.typescriptlang.org/play?ts=4.1.2#code/JYWwDg9gTgLgBAbzgVTAEwIYwKYEUCu2UAnnAL5wBmUEIcA5CBAHYDmEaARvQNwCwAKEHBmOKJQwBjbHABiECIkFwqCgFxwAzjCgjW-AWUGDK+ZpJjAWcHNoDqwGAAsA4tmZFgkgDwAVAMqSTtggGAB8ABQAlBqomDgERMR+gcGhYUoCKpIs2nD46FjYsYUJhCQpQSHhcAC8iGQGynDAlHARALJYTgB0UBjMaLTRcN5wAAw9AKxRmSrZufAA1tjEGtq6bHUMHgDuANKrvM0LzHkAbhgANoQaA6T1OoRNWfMF8dg9ACSa2PD1CBO8x6IIi7yK31+8AAPtCGlEADRAlQAbRWxAAuhpLjdsEDGs0jEJXlA-vgoMx8qVsAYiSYzBYrJTbDAHM4IPgYG4PLpJNESh9EhV5BAMoDXjkzvBwTgBUUhckRRkAQTiSpWu0us4+gMhiARmNJjM5vNJXl0esdHptvQ9odiMdXqcLtdbnB7tsnjTjE6qR9IX9tuL5sDQTLPj9A7D4Ujfaj0Vi4DjCPiDCo6SSyRS-UVaYIgA
The text was updated successfully, but these errors were encountered: