Skip to content

An opaque TypeScript type that matches all JS values, but with stricter type checking than `any`.

License

Notifications You must be signed in to change notification settings

dherman/ts-unknown

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

An opaque TypeScript type that matches all JS values, but with stricter type checking than `any`.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published