Closed
Description
TypeScript Version:
Nightly
Code
interface Foo {
userId: string
}
function hey (data: Foo & { userId: void }) {}
hey({ userId: undefined })
Expected behavior: Works. Even better, it would allow me to call it without userId
set at all.
Actual behavior:
index.ts(9,5): error TS2345: Argument of type '{ userId: undefined; }' is not assignable to parameter of type 'Foo & { userId: void; }'.
Type '{ userId: undefined; }' is not assignable to type 'Foo'.
Types of property 'userId' are incompatible.
Type 'undefined' is not assignable to type 'string'.
Edit: In case someone misses it in the title, enable strictNullChecks
on the nightly releases.
Edit 2: This seems like a big deal since the recommended way of dealing with Object.create(null)
is this.
Edit 3: I did also test replacing void
with undefined
, to the same result.