-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Discriminated unions constraints get ignored when used with Omit #30577
Copy link
Copy link
Closed
Labels
QuestionAn issue which isn't directly actionable in codeAn issue which isn't directly actionable in code
Description
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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
QuestionAn issue which isn't directly actionable in codeAn issue which isn't directly actionable in code