-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug
Description
TypeScript Version: 3.9.2 (also v4.0.0-beta)
Search Terms: omit, pick, union
Code
type StringTok = { name: 'string', location: number, contents: string }
type NumberTok = { name: 'number', location: number, value: number }
type Tok = StringTok | NumberTok
type UnlocatedTok = Omit<Tok, 'location'>
let a: UnlocatedTok = { name: 'number', value: 1 }
let b: UnlocatedTok = { name: 'number' }
Expected behavior:
No type error on the let a
, type error on the let b
.
Actual behavior:
Type error on the let a
:
Type '{ name: "number"; value: number; }' is not assignable to type 'Pick<Tok, "name">'.
Object literal may only specify known properties, and 'value' does not exist in type 'Pick<Tok, "name">'.(2322)
No type error on the let b
.
Specifically, it is surprising to me that, contrary to its description, the result of Omit<T, K>
is not the type which contains the members of T
except without the properties in K
, but instead some other type.
Playground Link: Link
Related Issues: None that I could find.
cmi23
Metadata
Metadata
Assignees
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug