To be honest I have no clue how to name this issue properly.
TypeScript Version: 3.4.0-dev.201xxxxx
Search Terms:
Code
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>
type ContextTitle =
{ title?: string } |
{ title: string, shortcut?: string }
type UselessStuff = {
name: string,
age: number
}
type DeleteStuff = Omit<UselessStuff, 'name'>
type T = ContextTitle & DeleteStuff
const a: T = {
age: 10,
shortcut: 'hey'
}
Expected behavior:
Get an error because I've defined shortcut, but not the required property title
Actual behavior:
Typescript does not report any error. Apparently it correctly detects the problem when using UselessStuff instead of the "Omitted" version.
Playground Link: http://www.typescriptlang.org/play/index.html#src=type%20Omit%3CT%2C%20K%20extends%20keyof%20T%3E%20%3D%20Pick%3CT%2C%20Exclude%3Ckeyof%20T%2C%20K%3E%3E%0A%0Atype%20ContextTitle%20%3D%0A%20%20%7B%20title%3F%3A%20string%20%7D%20%7C%0A%20%20%7B%20title%3A%20string%2C%20shortcut%3F%3A%20string%20%7D%0A%0Atype%20UselessStuff%20%3D%20%7B%0A%20%20name%3A%20string%2C%0A%20%20age%3A%20number%0A%7D%0A%0Atype%20DeleteStuff%20%3D%20Omit%3CUselessStuff%2C%20%27name%27%3E%0A%0A%0Atype%20T%20%3D%20ContextTitle%20%26%20DeleteStuff%0A%0Aconst%20a%3A%20T%20%3D%20%7B%0A%20%20age%3A%2010%2C%0A%20%20shortcut%3A%20%27hey%27%0A%7D%20%0A
To be honest I have no clue how to name this issue properly.
TypeScript Version: 3.4.0-dev.201xxxxx
Search Terms:
Code
Expected behavior:
Get an error because I've defined
shortcut, but not the required propertytitleActual behavior:
Typescript does not report any error. Apparently it correctly detects the problem when using
UselessStuffinstead of the "Omitted" version.Playground Link: http://www.typescriptlang.org/play/index.html#src=type%20Omit%3CT%2C%20K%20extends%20keyof%20T%3E%20%3D%20Pick%3CT%2C%20Exclude%3Ckeyof%20T%2C%20K%3E%3E%0A%0Atype%20ContextTitle%20%3D%0A%20%20%7B%20title%3F%3A%20string%20%7D%20%7C%0A%20%20%7B%20title%3A%20string%2C%20shortcut%3F%3A%20string%20%7D%0A%0Atype%20UselessStuff%20%3D%20%7B%0A%20%20name%3A%20string%2C%0A%20%20age%3A%20number%0A%7D%0A%0Atype%20DeleteStuff%20%3D%20Omit%3CUselessStuff%2C%20%27name%27%3E%0A%0A%0Atype%20T%20%3D%20ContextTitle%20%26%20DeleteStuff%0A%0Aconst%20a%3A%20T%20%3D%20%7B%0A%20%20age%3A%2010%2C%0A%20%20shortcut%3A%20%27hey%27%0A%7D%20%0A