0.1.0 • Published 8 months ago

@fenge/types v0.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

@fenge/types

npm.io npm.io npm.io npm.io PRs Welcome

A type patch for TypeScript, enhancing type-safe for built-in JavaScript apis.

Feature

Without this library:

  • 🚨 Array.isArray returns any[].
  • 🚨 JSON.parse returns any.
  • 🚨 new Map() generates Map<any, any>.
  • 🚨 <promise object>.catch accepts (reason: any) => void | PromiseLike<void>

With this library:

  • 👍 Array.isArray returns unknown[].
  • 👍 JSON.parse returns unknown.
  • 👍 new Map() generates Map<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

0.1.0

8 months ago

0.1.0-beta.0

8 months ago