8000 Unable to void object keys using `strictNullChecks` option · Issue #8904 · microsoft/TypeScript · GitHub
[go: up one dir, main page]

Skip to content
Unable to void object keys using strictNullChecks option #8904
Closed
@blakeembrey

Description

@blakeembrey

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    In DiscussionNot yet reached consensusSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0