@fenge/types
v0.1.0
Published
A type patch for TypeScript, enhancing type-safe for built-in JavaScript apis.
Downloads
262
Maintainers
Readme
@fenge/types
A type patch for TypeScript, enhancing type-safe for built-in JavaScript apis.
Feature
Without this library:
- 🚨
Array.isArray
returnsany[]
. - 🚨
JSON.parse
returnsany
. - 🚨
new Map()
generatesMap<any, any>
. - 🚨
<promise object>.catch
accepts(reason: any) => void | PromiseLike<void>
With this library:
- 👍
Array.isArray
returnsunknown[]
. - 👍
JSON.parse
returnsunknown
. - 👍
new Map()
generatesMap<unknown, unknown>
. - 👍
<promise object>.catch
accepts(reason: unknown) => void | PromiseLike<void>
Usage
Add a triple-slash-directive /// <reference types="@fenge/types" />
at the top of the ts file that serves as the entry point for your application or package. This will make the entire project more type-safe.
Application/Package Entry Point (eg: src/main.ts
or src/app.ts
)
/// <reference types="@fenge/types" />
import foo from "./foo";
Other File (eg: src/other-file.ts
)
console.log(JSON.parse('{"foo":"foo"}').bar);
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ❌ Object is of type 'unknown'.
Differences Between @total-typescript/ts-reset
- This library only focus on built-in ECMAScript apis. So it doesn't enhance the browser or Node apis like
fetch
. - This library only focus on type-safe, not convenience. So it doesn't contain the apis like
array-includes.d.ts
, which@total-typescript/ts-reset
does.
License
MIT