{"id":17038864,"url":"https://github.com/veetaha/ts-typedefs","last_synced_at":"2025-04-12T14:02:17.185Z","repository":{"id":34300529,"uuid":"175692140","full_name":"Veetaha/ts-typedefs","owner":"Veetaha","description":"A handy collection of TypeScript plain and generic type definitions and interfaces.","archived":false,"fork":false,"pushed_at":"2023-03-02T20:41:08.000Z","size":2224,"stargazers_count":13,"open_issues_count":8,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-26T08:37:27.493Z","etag":null,"topics":["essentials","type-level-programming","types","typescript","typescript-definitions","typescript-interfaces","typescript-library"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Veetaha.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-03-14T20:10:06.000Z","updated_at":"2024-06-23T04:54:41.000Z","dependencies_parsed_at":"2024-06-20T18:57:26.493Z","dependency_job_id":"2578fa71-c607-4791-85cb-d0d7d5f44202","html_url":"https://github.com/Veetaha/ts-typedefs","commit_stats":{"total_commits":106,"total_committers":3,"mean_commits":"35.333333333333336","dds":0.2075471698113207,"last_synced_commit":"dfb74e78eed029e7924bd8529f38f5cac20aa285"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Veetaha%2Fts-typedefs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Veetaha%2Fts-typedefs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Veetaha%2Fts-typedefs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Veetaha%2Fts-typedefs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Veetaha","download_url":"https://codeload.github.com/Veetaha/ts-typedefs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248578528,"owners_count":21127712,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["essentials","type-level-programming","types","typescript","typescript-definitions","typescript-interfaces","typescript-library"],"created_at":"2024-10-14T08:58:03.088Z","updated_at":"2025-04-12T14:02:17.151Z","avatar_url":"https://github.com/Veetaha.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003ets-typedefs\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://www.npmjs.com/package/ts-typedefs\"\u003e\n        \u003cimg \n            src=\"assets/jumbotron.png\" \n            width=\"500px\"\n        /\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\n---\n\n[![npm version](https://badge.fury.io/js/ts-typedefs.svg)](https://badge.fury.io/js/ts-typedefs)\n![npm](https://img.shields.io/npm/dm/ts-typedefs.svg?color=%2317c4b5)\n[![Build Status](https://travis-ci.com/Veetaha/ts-typedefs.svg?branch=master)](https://travis-ci.com/Veetaha/ts-typedefs)\n[![TypeScript](https://img.shields.io/badge/%3C%2F%3E-TypeScript-%230074c1.svg)](https://www.typescriptlang.org/)\n\nThis library is a handy collection of TypeScript plain and generic type definitions and interfaces **for both frontend and backend**. You may expect **zero runtime overhead** if you use imported items only in\ntype contexts.\n\n## [API documentation](https://veetaha.github.io/ts-typedefs/)\nGenerated by [typedoc](https://github.com/TypeStrong/typedoc)\n\n## [Contribution guidelines](CONTRIBUTING.md)\n\n## Credits\nThis project was inspired by ['ts-essentials'](https://github.com/krzkaczor/ts-essentials) library.\nSome type names were taken from them.\n\n## Quick API review\nThe most convenient way to explore `'ts-typedefs'` API is by easily browsing your *editor's completion \nlist* that shows signatures and descriptions for selected items. Types, functions, and classes names are intended to be super descriptive and intuitive. \nAll functional units provide *`typedoc` documentation in comments* so it is easy for\nIDEs to provide you with good hints.\n\n### Usage example\n```ts\nimport { DeepPartial, FilterProps, Func, Op } from 'ts-typedefs';\n\nclass User { /* ... */ }\ntype UserData = FilterProps\u003cUser, Op.NotExtends\u003cFunc\u003e\u003e;\n\nfunction updateUser(userUpd: DeepPartial\u003cUserData\u003e) { /* ... */ }\n```\n\n## Provided type definitions and runtime units\n\n* [Objects](#objects)\n    * [`Obj\u003c\u003e`](#objtvalues-tkeys)\n    * [`Class\u003c\u003e`](#classtinstance-targs)\n    * [`InstanceType\u003c\u003e (with abstract classes support)`](#instancetypetclass)\n    * [`ValueOf\u003c\u003e`](#valueoftobj)\n    * [`RemoveKeys\u003c\u003e`](#removekeystsrcobj-tkeysunion)\n    * [`FilterProps\u003c\u003e`](#filterpropstobj-tapprovecond)\n    * [`[Deep]MapValues\u003c\u003e`](#mapvaluestsrcobj-tmappedvalue)\n    * [`Merge\u003c\u003e`](#mergetobj1-tobj2)\n    * [`[Deep]Partial/Required\u003c\u003e`](#deeppartialrequiredtobj)\n    * [`[Deep]Readonly/Mutable\u003c\u003e`](#deepreadonlymutabletobj)\n    * [`OptionalLikelyUndefProps\u003c\u003e`](#optionallikelyundefpropstobj)\n    * [`...`](https://veetaha.github.io/ts-typedefs/modules/_types_objects_.html)\n* [Functions](#functions)\n    * [`[Async]Func\u003c\u003e`](#asyncfunctargs-tretval-tthis)\n    * [`AsyncFuncReturnType\u003c\u003e`](#asyncfuncreturntypetasyncfunc)\n    * [`...`](https://veetaha.github.io/ts-typedefs/modules/_types_functions_.html)\n* [Decorators](#decorators)\n    * [`MethodDecorator\u003c\u003e`](#methoddecoratortargs-tretval-tmethnamelimit)\n    * [`PropertyDecorator\u003c\u003e`](#propertydecoratortproptype-tpropnamelimit)\n    * [`...`](https://veetaha.github.io/ts-typedefs/modules/_types_decorators_.html)\n* [Logical](#logical)\n    * [`If\u003c\u003e`](#iftcond-tiftrue-telse-tifcondisbool)\n    * [`Not\u003c\u003e`](#nott-tiftisbool)\n    * [`And/Nand\u003c\u003e`](#andnandt)\n    * [`Or/Nor\u003c\u003e`](#ornort)\n    * [`[Not]Extends\u003c\u003e`](#notextendstextender-textendee)\n    * [`AreSame\u003c\u003e`](#aresamet1-t2)\n    * [`Is[Not]Any\u003c\u003e`](#isnotanytsuspect)\n    * [`Is[Not]Unknown\u003c\u003e`](#isnotunknowntsuspect)\n    * [`...`](https://veetaha.github.io/ts-typedefs/modules/_types_logical_.html)\n* [Runtime](#runtime)\n    * [`reinterpret()`](#reinterprettvalue-any-t)\n    * [`class Debug.UnreachableCodeError`](#class-debugunreachablecodeerror)\n    * [`...`](https://veetaha.github.io/ts-typedefs/modules/_runtime_index_.html)\n* [Misc](#misc)\n    * [`Tag\u003c\u003e`](#tagttarget-ttagname)\n    * [`UnionToIntersection\u003c\u003e`](#uniontointersectiontunion)\n    * [`UnpackPromise\u003c\u003e` ](#unpackpromisetpromise)\n    * [`PickAsOptional/Required/Readonly/Mutable/NullableProps\u003c\u003e`](#pickasoptionalrequiredreadonlymutablenullablepropstobj-tkeys)\n    * [`[Deep]Nullable\u003c\u003e`](#deepnullablet)\n    * [`Primitive`](#primitive)\n    * [`TypeName`](#typename)\n    * [`...`](https://veetaha.github.io/ts-typedefs/globals.html)\n    \n\nLet's see them in details.\n\n## Objects\n\n### [`Obj\u003cTValues, TKeys\u003e`](#provided-type-definitions-and-runtime-units \"Go back to contents\")\n\nDefines an object with keys of type `TKeys`, and all values of `TValue` type.\n```ts\ntype t0 = Obj;                      // { [key: string]: any; }     \ntype t1 = Obj\u003cboolean\u003e;             // { [key: string]: boolean; }     \ntype t2 = Obj\u003cstring, number\u003e;      // { [key: number]: string;  }\ntype t3 = Obj\u003cnumber, 'p1' | 'p2'\u003e; // { p1: number, p2: number; }\n```\n### [`Class\u003cTInstance, TArgs\u003e`](#provided-type-definitions-and-runtime-units \"Go back to contents\")\nDefines constructor function type that instantiates `TInstance` and accepts arguments of `TArgs` type.\n\n```ts\ninterface User { /* ... */ }\n\n// new (...args: any) =\u003e User\ntype t0 = Class\u003cUser\u003e;\n\n// new (...args: [string, number]) =\u003e User\ntype t1 = Class\u003cUser, [string, number]\u003e;\n```\n\n### [`InstanceType\u003cTClass\u003e`](#provided-type-definitions-and-runtime-units \"Go back to contents\")\n\nDefines an instance type of the given class or the type of its `prototype` property. \n`TClass` may even be an abstract class, though those ones are not newable, \nbut the type of their instances can be obtained through their `prototype` property.\n\n```ts\nimport { InstanceType } from 'ts-typedefs';\n\nclass User { id!: number; } // plain class\n\nfunction getAbstractUser() {\n    abstract class AbstractUser {  // local abstract class, its type is not\n        id!: number;               // accessible in the global namespace\n    }\n    return AbstractUser;\n}\n\ntype t0 = InstanceType\u003ctypeof User\u003e; // User\ntype t1 = InstanceType\u003cReturnType\u003ctypeof getAbstractUser\u003e\u003e; // AbstractUser\n```\n\n\n### [`ValueOf\u003cTObj\u003e`](#provided-type-definitions-and-runtime-units \"Go back to contents\")\n\nDefines a union type of all the values stored in `TObj`.\n```ts\ninterface User {\n    id:         number;\n    login:      string | null;\n    password:   string;\n    isDisabled: boolean;\n}\n/* number | string | null | boolean */\ntype t0 = ValueOf\u003cUser\u003e; \n/* union type of all properties and methods of `Array\u003cboolean\u003e` */\ntype t1 = ValueOf\u003cboolean[]\u003e; \n```\n\n### [`RemoveKeys\u003cTSrcObj, TKeysUnion\u003e`](#provided-type-definitions-and-runtime-units \"Go back to contents\")\nDefines the same object type as `TSrcObj`, but without `TKeysUnion` keys.\n```ts \ninterface User {\n    id:         number;\n    login:      string | null;\n    password:   string;\n    isDisabled: boolean;\n}\n/* \n{ \n    id:         number; \n    login:      string | null; \n    isDisabled: boolean; \n}\n*/\ntype t0 = RemoveKeys\u003cUser, 'password'\u003e; \n\n/* { id: number; } */\ntype t1 = RemoveKeys\u003cUser, 'password' | 'isDisabled' | 'login'\u003e;\n```\n\n### [`FilterProps\u003cTObj, TApproveCond\u003e`](#provided-type-definitions-and-runtime-units \"Go back to contents\")\nDefines the same type as `TObj` but with particular properties filtered out according to `TApproveCond`. `TApproveCond` is a boolean operator tree structure that defines the criteria that the filtered values must match. All these operators are defined in `Op` namespace.\n\n```ts\ninterface User {\n    id:         number;\n    login:      string | null;\n    password:   string;\n    isDisabled: boolean;\n    flag:       boolean;\n}\n\n/* { login: string;  } */\ntype t0 = FilterProps\u003cUser, Op.Extends\u003cstring\u003e\u003e; \n\n/* \n{ \n    isDisabled: boolean; \n    flag:       boolean; \n}\n*/\ntype t0 = FilterProps\u003cUser, Op.Extends\u003cboolean\u003e\u003e; \n\n/* \n{ \n    isDisabled: boolean; \n    flag:       boolean; \n    id:         number; \n}\n*/\ntype t1 = FilterProps\u003c\n    User, \n    Op.And\u003c[\n        Op.Not\u003cOp.UnionIncludes\u003cstring\u003e\u003e,  // Op.UnionExcludes\u003c\u003e is another option\n        Op.Nand\u003c[false, true, true, true]\u003e // this condition is always true\n    ]\u003e\n\u003e;\n```\nBecause of some TypeScript [limitations and bugs](https://stackoverflow.com/questions/55192212/typescript-circular-type-alias-produces-no-error-and-instead-widens-unit-types) `TApproveCond` tree must be not more than 5 levels deep (number of levels limitation may change, but it can only become greater).\n### [`MapValues\u003cTSrcObj, TMappedValue\u003e`](#provided-type-definitions-and-runtime-units \"Go back to contents\")\nDefines the same object type as `TSrcObj`, but all values of `TMappedValue` type.\n`DeepMapValues\u003c\u003e` variant maps values for all nested objects recursively.\n```ts\ninterface User {\n    login?: string | null;\n    friend: {\n        friendliness: number;\n        ref: User;\n    }\n}\n\n/* {  login: boolean; friend: boolean; } */\ntype t0 = MapValues\u003cUser, boolean\u003e;\n/*\n{\n    login: boolean;\n    friend: {\n        friendliness: boolean;\n        ref: DeepMapValues\u003cUser, boolean\u003e\n    }\n}\n*/\ntype t1 = DeepMapValues\u003cUser, boolean\u003e;\n\n```\n\n### [`Merge\u003cTObj1, TObj2\u003e`](#provided-type-definitions-and-runtime-units \"Go back to contents\")\nMerge objects `TObj1` and `TObj2`.\nProperties types from `TObj2` override the ones defined on `TObj1`.\nThis type is analogous to the return type of `Object.assign()`\n\n```ts\ninterface O1 {\n    p1: number;\n    p2: string;\n    p3: boolean;\n}\n\ninterface O2 {\n    p2: number | null;\n    p3: string;\n    p4: O1;\n}\n\n/*\n{ \n    p1: number; \n    p2: number | null;\n    p3: string;\n    p4: O1;\n}\n*/\ntype t0 = Merge\u003cO1, O2\u003e;\n\n/*\n{\n    p1: number;\n    p2: string;\n    p3: boolean;\n    p4: O1;\n}\n*/\ntype t1 = Merge\u003cO2, O1\u003e;\n```\n\n### [`[Deep]Partial/Required\u003cTObj\u003e`](#provided-type-definitions-and-runtime-units \"Go back to contents\")\n\n`Partial/Required\u003cTObj, TKeys = keyof TObj\u003e` defines the same type as `TObj` but \nwith all `TKeys` made optional/required.\n\n`DeepPartial/Required\u003c\u003e` defines the same type as `TObj` but with all properties made recursively `Partial/Required\u003c\u003e`.\n\nThis two types are actually exactly opposite to each other.\n\n```ts\ninterface User {\n    id: number;\n    name: {\n        first: string;\n    }\n}\n\n/*\n{\n    id?:   undefined | number;\n    name?: undefined | {\n        first: string;\n    }\n}\n*/\ntype PartUser = Partial\u003cUser, /* TKeys = keyof User */\u003e;\n\n/*\n{\n    id?:     number | undefined;\n    name?:   undefined | {\n        first?: string | undefined;\n    };\n}\n*/\ntype DeepPartUser = DeepPartial\u003cUser\u003e;\n\ntype RequUser     = Required\u003cUser, /* TKeys = keyof User */\u003e; // User\ntype DeepRequUser = DeepRequired\u003cDeepPartUser\u003e; // User\n```\n\n### [`[Deep]Readonly/Mutable\u003cTObj\u003e`](#provided-type-definitions-and-runtime-units \"Go back to contents\")\n\n`Readonly/Mutable\u003cTObj, TKeys = keyof TObj\u003e` defines the same type as `TObj` but \nwith all `TKeys` made readonly/mutable.\n\n`DeepReadonly/Mutable\u003c\u003e` defines the same type as `TObj` but with all properties made recursively `Readonly/Mutable\u003c\u003e`.\n\nThis two types are actually exactly opposite to each other.\n\n```ts\ninterface User {\n    id: number;\n    name: {\n        first: string;\n    }\n}\n\n/*\n{\n    readonly id: number;\n    readonly name: {\n        first: string;\n    }\n}\n*/\ntype RoUser = Readonly\u003cUser, /* TKeys = keyof User */\u003e;\n\n/*\n{\n    readonly id: number;\n    readonly name: {\n        readonly first: string;\n    };\n}\n*/\ntype DeepRoUser = DeepReadonly\u003cUser\u003e;\n\ntype MutUser     = Mutable\u003cRoUser, /* TKeys = keyof User */\u003e; // User\ntype DeepMutUser = DeepMutable\u003cDeepRoUser\u003e; // User\n```\n\n`DeepReadonly\u003c\u003e` is quite handy when you define deep readonly multidimensional arrays.\n\n```ts\ntype t0 = DeepReadonly\u003cnumber[][][]\u003e;\n// readonly (readonly (readonly number[])[])[]\n```\n\n### [`OptionalLikelyUndefProps\u003cTObj\u003e`](#provided-type-definitions-and-runtime-units \"Go back to contents\")\n\nDefines the same type as `TObj`, but adds 'optional' modifier `?` to all\nproperties that allow `undefined` as their value type (this includes `unknown` and `any`).\n\n```ts\ninterface User {\n    bio: string | undefined;\n    secret: unknown;\n    name: string;\n}\n\n/*\n{\n    bio?: string | undefined;\n    secret?: unknown;  \n    name: string;     // notice may-not-be `undefined` props don't get '?' modifier\n}\n*/\ntype RepairedUser = OptionalLikelyUndefProps\u003cUser\u003e;\n```\n\n## Functions\n\n### [`[Async]Func\u003cTArgs, TRetval, TThis\u003e`](#provided-type-definitions-and-runtime-units \"Go back to contents\")\nDefines a Function subtype with the given arguments, return type and `this` context. If it is `AsyncFunc\u003c\u003e` `TRetval` is packed into `Promise\u003cTRetval\u003e`\n\n```ts\ninterface User { /* ... */ }\n\n// (this: any, ...args: any) =\u003e unknown\ntype t0 = Func;                               \n\n// (this: any, ...args: [string, number | undefined]) =\u003e unknown\ntype t1 = Func\u003c[string, number | undefined]\u003e;\n\n// (this: any, ...args: [boolean]) =\u003e void\ntype t2 = Func\u003c[boolean], void\u003e;\n\n// (this: User,    ...args: [boolean]) =\u003e number\ntype t3 = Func\u003c[boolean], number, User\u003e;\n\n// (this: any, ...args: [string]) =\u003e Promise\u003cUser\u003e\ntype t4 = AsyncFunc\u003c[string], User\u003e\n```\n\n### [`AsyncFuncReturnType\u003cTAsyncFunc\u003e`](#provided-type-definitions-and-runtime-units \"Go back to contents\")\nDefines the unpacked result type of the `Promise` returned by the specified `TAsyncFunc`.\n\n```ts\nclass User {\n    static async getById(id: number): Promise\u003cUser\u003e {\n        // ...\n    }\n}\n\n// User\ntype t0 = AsyncFuncReturnType\u003cAsyncFunc\u003c[number], User\u003e\u003e;\n\n// User\ntype t1 = AsyncFuncReturnType\u003ctypeof User.getById\u003e\n```\n\n## Decorators\n\n### [`MethodDecorator\u003cTArgs, TRetval, TMethNameLimit\u003e`](#provided-type-definitions-and-runtime-units \"Go back to contents\")\nDefines a static or instance method decorator function type. `TArgs` tuple type limits the arguments' type decorated method accepts, `TRetval` limits the return type of the decorated method. `TMethNameLimit` defines the limitation for method names this decorator may be applied to.\n\n```ts\ndeclare function decor_any(): MethodDecorator;\ndeclare function decor_bool(): MethodDecorator\u003c[boolean]\u003e;\ndeclare function decor_getId(): MethodDecorator\u003cany[], any, 'getId'\u003e;\n\nfunction decor_str$num_bool(): MethodDecorator\u003c[string, number], boolean\u003e {\n    // argument types are automatically deduced and strongly typed here\n    return (protoOrClass, methodName, propDescriptor) =\u003e {\n        /* (this: typeof protoOrClass, ...args: [string, number]) =\u003e boolean */\n        const val = propDescriptor.value;\n        // ...\n    };\n};\n\nclass User {\n    @decor_getId()        // compile error (method name mismatch)\n    @decor_bool()         // compile error (params type mismatch)\n    @decor_str$num_bool() // compile error (params and return type mismatch)\n    @decor_any()          // works fine\n    meth0(bol: boolean, num: number): void {}\n\n    @decor_any()  // works fine\n    @decor_bool() // works fine\n    meth1(bol: boolean) {\n        return bol ? 32 : 'kek';\n    }\n\n    @decor_any()          // works fine\n    @decor_str$num_bool() // works fine\n    meth2(str: string, num: number) {\n        return !!str \u0026\u0026 !!num;\n    }\n\n    @decor_getId() // works fine\n    getId() { }\n}\n```\n\n### [`PropertyDecorator\u003cTPropType, TPropNameLimit\u003e`](#provided-type-definitions-and-runtime-units \"Go back to contents\")\nDefines a static or instance property decorator function type.\n\n```ts\ndeclare function decorateAny(): PropertyDecorator;\nfunction decorateStr(): PropertyDecorator\u003cstring\u003e {\n    return /* function arguments are analogously deduced */;\n};\nfunction decorIdProp(): PropertyDecorator\u003cnumber, 'id' | '_id'\u003e {\n    return /* function arguments are analogously deduced */;\n};\n\n\nexport class User {\n    @decorIdProp() // compile error (prop name and value type mismatch)\n    @decorateStr() // works fine\n    @decorateAny() // works fine\n    prop0!: string;\n\n    @decorIdProp() // compile error (prop name mismatch)\n    @decorateStr() // compile error (prop value type mismatch)\n    @decorateAny() // works fine\n    prop1!: number;\n\n    @decorIdProp() // works fine\n    @decorateStr() // compile error (prop value type mismatch)\n    @decorateAny() // works fine\n    _id!: number;\n\n    @decorIdProp() // compile error (prop value type mismatch)\n    @decorateStr() // works fine\n    @decorateAny() // works fine\n    id!: string;\n}\n```\n## Logical\n\n### [`If\u003cTCond, TIfTrue, TElse, TIfCondIsBool\u003e`](#provided-type-definitions-and-runtime-units \"Go back to contents\")\n\nSequentially performs the following logic:\n\nExpands to `TIfTrue`       if `TCond extends true`.\n\nExpands to `TElse`         if `TCond extends false`.\n\nExpands to `TIfCondIsBool` if `TCond extends boolean`.\n\n*As a convention, enclose `TCond` argument in parens.*\n\n```ts\ntype t0 = If\u003c(true), number, string\u003e;            // number\ntype t1 = If\u003c(false), number, string\u003e;           // string\ntype t2 = If\u003c(boolean), number, string, bigint\u003e; // bigint\n\ntype t3 = If\u003c(And\u003c[NotExtends\u003c22, number\u003e, true, true]\u003e),\n    string,\n    If\u003c(false),  // nested condition\n        number, \n        string\n\u003e\u003e; // string\n\n// You may use leading ampersand or pipe in order to explicitly separate branches visually\ntype t4 = If\u003c(true)\n    | number, // you may use \u0026 instead of |\n\n    | string\n\u003e; // number\n```\n\n### [`Not\u003cT, TIfTIsBool\u003e`](#provided-type-definitions-and-runtime-units \"Go back to contents\")\n\nDefines `false`      unit type if `T extends true`.\nDefines `true`       unit type if `T extends false`.\nDefines `TIfTIsBool` when `T` is exactly `boolean` type.\n\n```ts\ntype t0 = Not\u003ctrue\u003e;            // false\ntype t1 = Not\u003cfalse\u003e;           // true  \ntype t2 = Not\u003cboolean, number\u003e; // number\ntype t3 = Not\u003cNot\u003ctrue\u003e\u003e;       // true\n```\n### [`And/Nand\u003cT\u003e`](#provided-type-definitions-and-runtime-units \"Go back to contents\")\n\nDefines `true` or `false` accroding to the definition of `and/nand(negated and)` logical operator.\nIt gets applied to all the argumets in the given tuple type `T`.\n\n```ts\ntype t0 = And\u003c[true, true, true]\u003e; // true\ntype t1 = And\u003ctrue[]\u003e;             // true\ntype t2 = And\u003c[true, false, true]\u003e // false\n\ntype t3 = And\u003cboolean[]\u003e;          // false\ntype t4 = And\u003c[boolean, true]\u003e;    // false\n\ntype t5 = Nand\u003c[true, true]\u003e;      // false\n```\n\n### [`Or/Nor\u003cT\u003e`](#provided-type-definitions-and-runtime-units \"Go back to contents\")\n\nDefines `true` or `false` accroding to the definition of `or/nor(negated or)` logical operator.\nIt gets applied to all the argumets in the given tuple type `T`.\n\n```ts\ntype t0 = Or\u003c[false, false, false]\u003e; // false\ntype t1 = Or\u003cfalse[]\u003e;               // false\ntype t2 = Or\u003c[false, true, false]\u003e   // true\n\ntype t3 = Or\u003cboolean[]\u003e;             // true\ntype t4 = Or\u003c[boolean, false]\u003e;      // true\n\ntype t5 = Nor\u003c[true, true]\u003e;         // false\n```\n\n### [`[Not]Extends\u003cTExtender, TExtendee\u003e`](#provided-type-definitions-and-runtime-units \"Go back to contents\")\n\nDefines `true` if `TExtender` is assignable to `TExtendee`, otherwise `false`.\n\nIt verifies that you may physically assign a value of type `TExtender` to `TExtendee`.\nThat's why union types with excess members that are not assignable to `TExtendee`\nwill evaluate to `false`.\n\n```ts\ntype t0 = Extends\u003cstring | null, string\u003e; // false\ntype t1 = Extends\u003ctrue, boolean\u003e;         // true\ntype t2 = Extends\u003cnever, never\u003e;          // true\n\ntype t3 = NotExtends\u003c22, number\u003e;         // false\n```\n\n### [`AreSame\u003cT1, T2\u003e`](#provided-type-definitions-and-runtime-units \"Go back to contents\")\n\nDefines `true` if `T1` is exactly `T2`, `false` otherwise.\nEven `AreSame\u003cunknown, any\u003e` expands to `false`. Only the same types expand to `true`. \n\nIt doesn't tolerate co/bi/contravaraince, only the types of exactly the same shapes (excluding function types limitation) will cause to return `true`.\n\nBeware that this type works as vanilla `extends` clause with function types,\nso comparing functions is not that strict.\n\n```ts\ntype t0 = AreSame\u003c{}, { num: number }\u003e; // false\ntype t1 = AreSame\u003c\n    { num: number, str: string }, \n    { num: number, str: string }\n\u003e; // true\ntype t2 = AreSame\u003cany, unknown\u003e;        // false   \ntype t8 = AreSame\u003cFunc, Func\u003e;          // true\ntype t9 = AreSame\u003c[number], [number]\u003e;  // true\ntype t10 = AreSame\u003c[number, string], [number]\u003e; // false\n```\n\n### [`Is[Not]Any\u003cTSuspect\u003e`](#provided-type-definitions-and-runtime-units \"Go back to contents\")\n\nDefines `true[false]` if `TSuspect` is exactly of `any` type, `false[true]` otherwise.\n\n```ts\ntype t0 = IsAny\u003cany\u003e;        // true\ntype t1 = IsAny\u003cunknown\u003e;    // false\ntype t2 = IsAny\u003cnever\u003e;      // false\ntype t3 = IsAny\u003cstring\u003e;     // false\n\ntype t4 = IsNotAny\u003cany\u003e;     // false\ntype t5 = IsNotAny\u003cunknown\u003e; // true\n// ...\n```\n\n### [`Is[Not]Unknown\u003cTSuspect\u003e`](#provided-type-definitions-and-runtime-units \"Go back to contents\")\n\nDefines `true[false]` if `TSuspect` is exactly of `unknown` type, `false[true]` otherwise.\n\n```ts\ntype t0 = IsUnknown\u003cunknown\u003e;  // true\ntype t1 = IsUnknown\u003cboolean\u003e;  // false\n\ntype t2 = IsNotUnknown\u003cnever\u003e; // true\n// ...\n```\n\n## Runtime\n\n### [`reinterpret\u003cT\u003e(value: any): T`](#provided-type-definitions-and-runtime-units \"Go back to contents\")\n\nC++ style operator, a syntactic sugar for writing casts like \n`value as any as T` when a simple `value as T` cast cannot be performed. \nUse it with caution! \n\nThis function is actually noop at runtime, all it does is it suppresses \n*'inability to cast'* *tsc* error. It's better to use this function rather than\n`value as any as T` cast, because it amplifies your attention to such uneven\nplaces in code and it may be easier to do a \u003ckbd\u003eCtrl\u003c/kbd\u003e + \u003ckbd\u003eF\u003c/kbd\u003e search for these.\n\n```ts\ninterface User {\n // ...\n}\ntype UserUpdate = DeepPartial\u003cRemoveKeys\u003cUser, 'password'\u003e\u003e;\n\nconst userUpd: UserUpdate = // ...\n\nObject.assign(userUpd, { \n    password: 'somepassword-pfff', otherRequiredFields: // ...\n});\n\n// For future devs: reinterpreting here, because userUpd has the same shape as `User`\nlet user = reinterpret\u003cUser\u003e(userUpd); \n\n// `typeof user` is `User` \n```\n \n### [`class Debug.UnreachableCodeError`](#provided-type-definitions-and-runtime-units \"Go back to contents\")\nClass used to perform `never` type value checks in unreachable code.\n\n\n```ts\nconst val: string | number;\n\n\nif (typeof val === 'string') {\n     return null;\n} else if (typeof val === 'number') {\n     throw new Debug.UnreachableCodeError(val); // compiler error: val is not of type `never` here\n     return;\n} else {\n     throw new Debug.UnreachableCodeError(val); // this is ok val has `never` type here\n}\n\nenum Enum {\n    A, B, C\n}\nlet suspect: Enum = // ...\nswitch (suspect) {\n    case Enum.A: return;\n    case Enum.B: return;\n    default: {\n        // compiler error, this path is reachable\n        // as we didn't handle `suspect === Enum.C` case\n        throw new Debug.UnreachableCodeError(suspect);\n    }\n}\n```\n\n## Misc\n\n### [`Tag\u003cTTarget, TTagName\u003e`](#provided-type-definitions-and-runtime-units \"Go back to contents\")\nDefines nominal type by adding a property with `TTagName` value to `TTarget`.\n`TTagName` must be unique across your application, treat it like the name of\nyour nominal type.\n\nWith this type, you may pick particular subclass of values from the given type and force\nyour clients to filter other values that are assignable to `TTarget` but don't\nobey to your prerequisites, thus making them pay more attention to them.\n\n```ts\ntype PositiveInt = Tag\u003cnumber, 'PositiveInt'\u003e;\ntype CsvString   = Tag\u003cstring, 'CsvString'\u003e;\n\n// Prerequisites: `userId \u003e 0`\nasync function getUser(userId: PositiveInt) {\n     return userRepository.findById(userId);\n}\n\n// Prerequisites: given string must be valid csv\nfunction parseCsv(csvString: CsvString) {\n     // Here you may be sure that client payed attention to checking the input\n\n     const lines = csvString.split('\\n').map(line =\u003e line.split(','));\n}\n\ngetUser(-2);                // compile error\ngetUser(58);                // compile error\ngetUser(58 as PositiveInt); // fine (explicit cast pays your attention to prerequisites)\n\nparseCsv('\\nbla bla');      // compile error\nparseCsv('a,b,c\\nd,e,f' as CsvString);   // fine\n```\n\n### [`UnionToIntersection\u003cTUnion\u003e`](#provided-type-definitions-and-runtime-units \"Go back to contents\")\n\nDefines an intersection type of all union's items.\n\nBecause of TypeScript boolean representation as `type boolean = true | false`\nyou get the following result:\n`UnionToIntersection\u003cboolean\u003e` is `true \u0026 false`\n\n```ts\n// string \u0026 number \u0026 number[]\ntype t0 = UnionToIntersection\u003cstring | number | number[]\u003e;\n```\n\n### [`UnpackPromise\u003cTPromise\u003e`](#provided-type-definitions-and-runtime-units \"Go back to contents\") \nDefines the type of value, which is passed to `TPromise.then(cb)` `cb` callback.\n\n```ts\ntype t0 = UnpackPromise\u003cPromise\u003cnumber\u003e\u003e; // number;\ntype t1 = UnpackPromise\u003cPromise\u003cvoid\u003e\u003e;   // void;\n\n// Promise\u003cstring\u003e;\ntype t2 = UnpackPromise\u003c\n    Promise\u003cPromise\u003cstring\u003e\u003e\n\u003e; \n\n// string\ntype t3 = UnpackPromise\u003cUnpackPromise\u003c\n    Promise\u003cPromise\u003cstring\u003e\u003e\n\u003e\u003e;\n```\n\n### [`PickAsOptional/Required/Readonly/Mutable/NullableProps\u003cTObj, TKeys\u003e`](#provided-type-definitions-and-runtime-units \"Go back to contents\")\n\nShorthand for `Partial/Required/Readonly/Mutable/NullableProps\u003cPick\u003cTObj, TKeys\u003e\u003e`, but better optimized (into one mapped object type).\n\n```ts\ninterface User {\n    readonly id: number;\n    name?: string;\n    bio: string;\n}\nPickAsOptional\u003cUser, 'name' | 'id'\u003e === Partial\u003cPick\u003cUser, 'name' | 'id'\u003e\u003e\nPickAsRequired\u003cUser, 'name' | 'id'\u003e === Required\u003cPick\u003cUser, 'name' | 'id'\u003e\u003e\nPickAsReadonly\u003cUser, 'name' | 'id'\u003e === Readonly\u003cPick\u003cUser, 'name' | 'id'\u003e\u003e\n\n// ...\n```\n\n\n### [`[Deep]Nullable\u003cT\u003e`](#provided-type-definitions-and-runtime-units \"Go back to contents\")\n`Nullable\u003cT\u003e` defines type `T` that may also be `null` or `undefined`:\n```ts\nexport type Nullable\u003cT\u003e = T | undefined | null;\n```\n\n`DeepNullable\u003cT\u003e` defines the same type as `TObj` but with all properties made `NonNullable\u003c\u003e` recursively.\n\n```ts\ninterface User {\n    id: number;\n    name: {\n        first: string;\n        last:  string;\n    };\n}\n\n/*\nNullable\u003c{\n    id?:  Nullable\u003cnumber\u003e;\n    name?: Nullable\u003c{\n        first?: Nullable\u003cstring\u003e;\n        last?:  Nullable\u003cstring\u003e;\n    }\u003e;\n}\u003e\n*/\ntype t0 = DeepNullable\u003cUser\u003e;\n```\n\n### [`Primitive`](#provided-type-definitions-and-runtime-units \"Go back to contents\")\nDefines a union of all possible value types defined in the language,\n`null` and `undefined` are considered to be primitive types.\n\n```ts\nexport type Primitive = (\n    | number \n    | string \n    | boolean  \n    | undefined \n    | symbol \n    | null\n    | bigint\n);\n```\n\n\n### [`TypeName`](#provided-type-definitions-and-runtime-units \"Go back to contents\")\n\nDefines a union of all possible strings retuned by applying `typeof` operator.\n\n```ts\nexport type TypeName = (\n    | 'number'    \n    | 'string' \n    | 'boolean'  \n    | 'undefined' \n    | 'object' \n    | 'function' \n    | 'symbol'\n    | 'bigint'\n);\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fveetaha%2Fts-typedefs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fveetaha%2Fts-typedefs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fveetaha%2Fts-typedefs/lists"}