@tolokoban/type-guards
TypeScript icon, indicating that this package has built-in type declarations

0.5.0 • Public • Published

@tolokoban/type-guards

import { assertType } from "@tolokoban/type-guards"

interface Article {
    id: string
    name: string
    price: number
}

function printArticles(data: unknown): Article[] {
    assertType<Article[]>(
        data,
        [
            "array", {
                id: "string",
                name: "string",
                price: "number"
            }
        ]
    )
    for (const article of data) {
        console.log(`#{article.name} #${article.id}`)
    }
}

Readme

Keywords

none

Package Sidebar

Install

npm i @tolokoban/type-guards

Weekly Downloads

0

Version

0.5.0

License

none

Unpacked Size

20.7 kB

Total Files

8

Last publish

Collaborators

  • tolokoban