Skip to content

Handle missing properties correctly #434

Closed
@leilapearson

Description

@leilapearson

🐛 Bug report

Current Behavior

const T = t.type({ a: t.unknown })
assert.strictEqual(T.is({}), true) // property 'a' is missing, but the type check still passes

Expected behavior

const T = t.type({ a: t.unknown })

// property 'a' is missing but must be present
assert.strictEqual(T.is({}), false) 

// property 'a' is present, and undefined is a valid value for unknown
assert.strictEqual(T.is({ a: undefined }), true) 

// property 'a' is present, and null is a valid value for unknown
assert.strictEqual(T.is({ a: null }), true) 

Similarly, in vanilla TypeScript:

type T = { a: unknown }

// won't compile
const T1: T = { } 

// good
const T2: T = { a: undefined } 

// good
const T3: T = { a: null } 

Reproducible example

See above

Suggested solution(s)

Will submit a pull request.

Additional context

Your environment

Software Version(s)
io-ts master
fp-ts 2.0.0
TypeScript 3.7.4

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions