TypeScript Treasure

raw JSON →
0.0.12 verified Sat Apr 25 auth: no javascript

A collection of TypeScript type utilities inspired by a coding style called MuGuaTS. Provides generic tools like If_Num, If_Str, If_Bool, If_Arr, If_Obj, If_Nul, If_Und, If_Never, If_Any, If_Unknown, If_Union, If_Equal, If_Includes, If_Some, If_Every, If_Key, If_Val, If_Readonly, If_Optional, If_Required, If_Mutable, If_Writable, If_Fn, If_Tuple, etc. Current stable version 0.0.12. Release cadence is infrequent; appears to be a side project. Differentiators: opinionated naming convention and one-line/multi-line formatting rules aimed at readability.

error Cannot find module 'typescript-treasure' or its corresponding type declarations.
cause Package not installed or not in tsconfig paths.
fix
Run 'npm install typescript-treasure' and ensure 'typescript-treasure' is in node_modules types.
error 'If_Num' is not exported from 'typescript-treasure'.
cause Typo or using default import instead of named.
fix
Use import { If_Num } from 'typescript-treasure'.
error Type 'If_Num<42>' is not assignable to type 'boolean'.
cause If_Num returns a type (true/false), not a runtime value.
fix
Use If_Num<42> extends true ? ... : ... pattern.
gotcha All utility types are prefixed with 'If_' and use underscores after 'If'. Incorrect casing (e.g., 'IfNum') will cause type errors.
fix Use correct names like 'If_Num', 'If_Str'.
gotcha Package is not tree-shakeable in all bundlers due to possible barrel exports; importing unused utilities may increase bundle size in some setups.
fix Use import destructuring and ensure bundler supports tree shaking (e.g., ES modules).
gotcha Documentation is primarily in Chinese; English docs may be incomplete or missing.
fix Refer to inline type comments or experiment with the utilities directly.
npm install typescript-treasure
yarn add typescript-treasure
pnpm add typescript-treasure

Demonstrates usage of several type utilities: If_Num, If_Str, If_Bool, If_Equal, If_Includes with example types.

import { If_Num, If_Str, If_Bool, If_Equal, If_Includes } from 'typescript-treasure';

type Test1 = If_Num<42>; // true
type Test2 = If_Str<'hello'>; // true
type Test3 = If_Bool<false>; // true
type Test4 = If_Equal<1, 2>; // false
type Test5 = If_Includes<[1, 2, 3], 2>; // true