Closed
Description
TypeScript Version: [email protected] (also happens in 2.7.2)
tested with unmodified tsconfig generated by tsc --init
Search Terms: intersection mapped types restrictions
Code
type locales = 'us' | 'jp' | 'nz'
type YZ = {
[routeName: string]: {someRandomProperty?:string} & { // this does not throw the error!
// [routeName: string]: {} & { // this will throw the error!
// [routeName: string]: { // just like this!
// [routeName: string]: undefined & { // or this!
urls: {
[P in locales]?: string;
}
}
}
let value: YZ = {
'hello': {
urls: {
jp: 'dragon',
ph: 'unknown'
}
}
};
Expected behavior:
There should be an error message along the lines of Type '{ jp: string; ph: string; }' is not assignable to type '{ us?: string | undefined; jp?: string | undefined; nz?: string | undefined; }'. Object literal may only specify known properties, and 'ph' does not exist in type '{ us?: string | undefined; jp?: string | undefined; nz?: string | undefined; }'
Actual behavior:
No error message is thrown :(
Playground Link:
Playground never shows the error message for some reason.
Related Issues: