{"id":15882,"library":"typescript-is","title":"TypeScript-is","description":"typescript-is is a TypeScript compiler transformer that generates runtime type-check functions directly from static TypeScript types. It automates the process of creating type predicates for `any` or `unknown` data, which is common when working with external data sources like API responses or user-uploaded files. The library inspects type definitions at compile time and emits JavaScript functions that meticulously validate incoming objects against those definitions. Currently at version 0.20.0, the project is officially deprecated and will not be updated for TypeScript versions 4.8 and above. Users are strongly advised to migrate to `typia` for newer TypeScript environments. Before its deprecation, the project aimed for regular, feature-driven releases. Its core differentiator lies in leveraging the TypeScript compiler API to avoid manual type predicate writing, aiming for comprehensive type-safety at runtime for serializable JavaScript objects.","status":"deprecated","version":"0.20.0","language":"javascript","source_language":"en","source_url":"https://github.com/woutervh-/typescript-is","tags":["javascript","TypeScript","compiler","transformer","type"],"install":[{"cmd":"npm install typescript-is","lang":"bash","label":"npm"},{"cmd":"yarn add typescript-is","lang":"bash","label":"yarn"},{"cmd":"pnpm add typescript-is","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency required for the TypeScript compiler transformer to operate.","package":"typescript","optional":false},{"reason":"Required for using decorator-based type assertions (`ValidateClass`, `AssertType`).","package":"reflect-metadata","optional":true}],"imports":[{"note":"This function call is a placeholder transformed at compile-time by the `typescript-is` plugin. Without the plugin configured via `ttypescript`, it will not perform runtime checks and often resolve to `any`.","wrong":"const { is } = require('typescript-is');","symbol":"is","correct":"import { is } from 'typescript-is';"},{"note":"Throws a `TypeError` if the value does not conform to the specified type. Like `is`, this call is transformed by the compiler plugin; it requires `ttypescript` to function correctly at runtime.","wrong":"assertEquals<Type>(value); // Used without ttypescript configured","symbol":"assertEquals","correct":"import { assertEquals } from 'typescript-is';"},{"note":"This is not a direct import into source code but an entry in the `compilerOptions.plugins` array within `tsconfig.json`, used by `ttypescript` to inject the compiler transformer.","wrong":"{ \"transform\": \"typescript-is/transformer\" }","symbol":"Transformer Configuration","correct":"{ \"transform\": \"typescript-is/lib/transform-inline/transformer\" }"}],"quickstart":{"code":"{\n  \"compilerOptions\": {\n    \"target\": \"es2018\",\n    \"module\": \"commonjs\",\n    \"strict\": true,\n    \"esModuleInterop\": true,\n    \"plugins\": [\n      { \"transform\": \"typescript-is/lib/transform-inline/transformer\" }\n    ]\n  },\n  \"include\": [\"src/**/*.ts\"]\n}\n\n// package.json (excerpt)\n// ...\n// \"scripts\": {\n//   \"build\": \"ttsc\",\n//   \"start\": \"node dist/index.js\"\n// }\n// ...\n\n// src/index.ts\nimport { assertEquals } from 'typescript-is';\n\ninterface User {\n  id: number;\n  name: string;\n  email?: string;\n}\n\nfunction processUserData(data: unknown) {\n  try {\n    // This call is transformed by typescript-is to perform runtime checks\n    assertEquals<User>(data);\n    console.log(\"User data is valid:\", data);\n    // At this point, 'data' is safely typed as User\n    console.log(`Processing user ${data.name} (ID: ${data.id})`);\n  } catch (error: any) {\n    console.error(\"Invalid user data:\", error.message);\n  }\n}\n\n// Example valid data\nprocessUserData({ id: 1, name: \"Alice\", email: \"alice@example.com\" });\nprocessUserData({ id: 2, name: \"Bob\" });\n\n// Example invalid data\nprocessUserData({ id: \"3\", name: \"Charlie\" }); // ID is string, expected number\nprocessUserData({ id: 4 }); // Missing name\nprocessUserData({ id: 5, name: \"David\", age: 30 }); // Extra property (strict)\n","lang":"typescript","description":"This quickstart demonstrates how to configure `typescript-is` with `ttypescript` in `tsconfig.json` and use `assertEquals` to perform runtime type validation on an `unknown` input, ensuring type safety for `User` objects. It shows both valid and invalid data scenarios."},"warnings":[{"fix":"Migrate to the recommended alternative, `typia` (https://github.com/samchon/typia), or another actively maintained runtime type-checking library for TypeScript.","message":"`typescript-is` is officially deprecated and will not receive updates or support for TypeScript versions 4.8 and higher. Continuing to use it with newer TypeScript versions may lead to build failures or unexpected behavior.","severity":"breaking","affected_versions":">=4.8.0-ts"},{"fix":"Ensure `transpileOnly` is set to `false` or use `ttypescript` as the compiler in your build setup, which explicitly supports transformers.","message":"When using bundlers or loaders like `ts-loader` with the `transpileOnly` flag set to `true`, TypeScript transformers are bypassed. This means `typescript-is` will not apply its type transformations, leading to no runtime checks.","severity":"gotcha","affected_versions":">=0.17.0"},{"fix":"Install `ttypescript` (`npm install --save-dev ttypescript`), configure your `tsconfig.json` with the transformer plugin, and run your build using `ttsc` instead of `tsc`.","message":"`typescript-is` relies on a TypeScript compiler transformer, which is not natively supported by `tsc`. It requires `ttypescript` or programmatic configuration of the TypeScript API to inject the transformer into your build process.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Review the types you are attempting to validate. For types involving functions, use the `functionBehavior` option in `tsconfig.json` to either ignore or perform a simple `typeof` check. Avoid using `typescript-is` for deeply complex, non-serializable type structures.","message":"The library is designed to generate type predicates for *serializable* JavaScript objects. It will not work for types that involve non-serializable constructs like functions, classes (unless configured with decorators and `reflect-metadata`), or complex symbols, without specific configuration or limitations.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Ensure `ttypescript` is installed, `tsconfig.json` correctly points to the transformer (`\"transform\": \"typescript-is/lib/transform-inline/transformer\"`), and the build command uses `ttsc` instead of `tsc`.","cause":"The `typescript-is` transformer was not successfully integrated into the build process, or `ttypescript` was not used/configured correctly.","error":"Error: No transformer was applied. Did you forget to configure 'ttypescript' or your bundler?"},{"fix":"Inspect the input data and the target type definition (e.g., `interface Foo { foo: string; }`) to identify the mismatch. Adjust the data to fit the type or refine the type definition.","cause":"The runtime data provided to `assertEquals` or `is` did not conform to the expected TypeScript type definition, specifically missing the 'foo' property.","error":"Validation failed at $: expected 'foo' in object, found: {}"},{"fix":"Configure the `functionBehavior` option in your `tsconfig.json` plugin settings. Options include `ignoreFunctions` (to skip function validation) or `typeof` (to perform a basic `typeof 'function'` check).","cause":"Attempted to validate a TypeScript type that includes a function signature (e.g., `type MyType = { handler: () => void }`) without explicit handling.","error":"TypeError: Function calls are not supported at runtime by `typescript-is`. Consider using `functionBehavior`."}],"ecosystem":"npm"}