New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

rtt

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rtt

Runtime Typescript Types

latest
Source
npmnpm
Version
1.0.2
Version published
Maintainers
1
Created
Source

rtt

Runtime Typescript Types

Overview

This package provides a way to store type information in objects and check types at runtime in TypeScript. It is useful for scenarios where you need runtime type introspection, such as serialization, validation, or building type-safe APIs.

Features

  • Attach type metadata to objects.
  • Check if an object is of a specific type at runtime using the is function.
  • Support for type hierarchies and generics.

Installation

npm install rtt

Usage

import {$NewType, is, Model} from 'rtt';

// Define types
const $A = () => $NewType('MyPackage', 'A');
const $B = () => $NewType('MyPackage', 'B', $A());

// Create a model instance
const model: Model = {
  $type: $B(),
};

// Runtime type checks
is(model, $B()); // true
is(model, $A()); // true (because B extends A)

API

$NewType(packageName: string, typeName: string, parent?, generics?)

Creates a new runtime type.

is(model: any, type: $Type): boolean

Checks if the given model is of the specified type (or its parent).

Model

Interface for objects with runtime type information.

Keywords

Typescript

FAQs

Package last updated on 07 Sep 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts