Skip to content

About

A set of classes and utilities for JavaScript type inspection and validation.

Topics

Resources

Stars

2 stars

Watchers

1 watching

Forks

Repository files navigation

@tsdotnet/reflection: Ask a value what it is. Runtime type checks that narrow.

npm version GitHub license

Runtime type inspection with typeInfo, and TypeValidator for checking the shape of unknown values.

Install

npm install @tsdotnet/reflection

Usage

import { typeInfo } from '@tsdotnet/reflection';

typeInfo(42).isValidNumber;      // true
typeInfo('a').isString;          // true
typeInfo(null).isNullOrUndefined; // true

TypeValidator<T> (the default export) is built from a descriptor object; isSubsetOf(value) checks the value has at least those members and narrows it to T.

Use it from

ESM (import { typeInfo } from '@tsdotnet/reflection';) or CommonJS (const { typeInfo } = require('@tsdotnet/reflection');).

In a browser, without a bundler
<script src="https://cdn.jsdelivr.net/npm/@tsdotnet/type@1/dist/umd/type.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@tsdotnet/compare@1/dist/umd/compare.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@tsdotnet/reflection@1/dist/umd/reflection.min.js"></script>
<script>
  const { typeInfo } = tsdotnet.reflection;
</script>

Docs

tsdotnet.github.io/reflection

About

A set of classes and utilities for JavaScript type inspection and validation.

Topics

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages