ts-unknown
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

The unknown type

This repo defines a TypeScript type called unknown. Like any, unknown applies to all JavaScript values, but it results in much stricter type checking. For example, extracting properties from an object of type any results in another any value:

let a: any = { foo: "bar" };

a.foo // any

By contrast, you can't even extract a property from the type unknown without asserting it to be an object first:

let u: unknown = { foo: "bar" };

// a.foo // type error
(a as { foo: string }).foo // string

/ts-unknown/

    Package Sidebar

    Install

    npm i ts-unknown

    Weekly Downloads

    1

    Version

    0.2.0

    License

    MIT

    Last publish

    Collaborators

    • dherman