tsdjs/tsd

`unknown` function parameter passes all type checks

Opened this issue · 0 comments

When a function parameter is of type unknown, it is allowed for all type checks. All 3 of the latter checks here should fail:

import * as tsd from 'tsd'

const example1 = (value: number) => String(value)

tsd.expectType<(value: number) => string>(example1) // true positive
tsd.expectType<(value: string) => string>(example1) // true negative
tsd.expectType<(value: Date) => string>(example1) // true negative

const example2 = (value: unknown) => String(value)

tsd.expectType<(value: number) => string>(example2) // FALSE POSITIVE
tsd.expectType<(value: string) => string>(example2) // FALSE POSITIVE
tsd.expectType<(value: Date) => string>(example2) // FALSE POSITIVE

Playground