@maboroshi/type-assertions
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

type-assertions

型アサーションユーティリティ
https://github.com/maboroshi-inc/type-assertions

インストール

npm install @maboroshi/type-assertions

or

yarn add @maboroshi/type-assertions

使い方

Asserts API

TypeScript 3.7 より提供された Assertion Function を用いた型アサート機能を提供する。

import { Asserts } from '@maboroshi/type-assertions'

const fn = (value: number | null) => {
  Asserts.isNumber(value)
  return value.toString()
}

fn(123) // => `123`
fn(null) // => throw error!

Guards API

Type Guard 機能を提供する。

import { Guards } from '@maboroshi/type-assertions'

const fn = (value: number | null) => {
  if (Guards.isNumber(value)) {
    return value.toString()
  }
}

fn(123) // => `123`
fn(null) // => undefined

API

API ドキュメント を見る

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.2
    0
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.2
    0
  • 1.0.1
    0
  • 1.0.0
    0

Package Sidebar

Install

npm i @maboroshi/type-assertions

Weekly Downloads

0

Version

1.0.2

License

MIT

Unpacked Size

46.8 kB

Total Files

10

Last publish

Collaborators

  • isoden