Skip to content

unknown function parameter passes all type checks #212

@ehaynes99

Description

@ehaynes99

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions