Skip to content

Apparent properties in union of primitive and object causes incorrect error #31668

Closed
@bjornstar

Description

@bjornstar

TypeScript Version: 3.5.1

Search Terms: sub blink sup bold HTML Element String.prototype methods

Code

type sign = (payload: string | object) => void;
const sign: sign = (payload) => { console.log(payload)}
sign({ sub: null })

Expected behavior: Ok

Actual behavior:

$ ./node_modules/.bin/tsc --version
Version 3.5.1
$ ./node_modules/.bin/tsc --lib es2015 --strict ./repro.ts
repro.ts:5:6 - error TS2326: Types of property 'sub' are incompatible.
  Type 'null' is not assignable to type '(() => string) | undefined'.

5 sign({ sub: null })
       ~~~~~~~~~~~~~


Found 1 error.
$ ./node_modules/.bin/tsc --version
Version 3.6.0-dev.20190530
$ ./node_modules/.bin/tsc --lib es2015 --strict ./repro.ts
repro.ts:5:6 - error TS2326: Types of property 'sub' are incompatible.
  Type 'null' is not assignable to type '(() => string) | undefined'.

5 sign({ sub: null })
       ~~~~~~~~~~~~~


Found 1 error.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScript

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions