typescript-remove-index-signature-using-mapped-types-remove-index-signature-using-mapped-types
export type KnownKeys<T> = {
[K in keyof T]: string extends K ? never : number extends K ? never : K
} extends { [_ in keyof T]: infer U } ? U : never;
interface Options {
key: string;
title: string;
[dataProperty: string]: string | number;
}
type KnownKeysOfOptions = KnownKeys<Options>; // 'key' | 'title';
// (vs. type KeysOfOptions = keyof Options // string | number;)
Type cast an argument. If no type is provided it will default to any
export const Cast = <T = any>(arg: any): T => arg;
Example on overloading private functions
export function someFunction(arg1: string, arg2 = false) {
return someFunction;
function someFunction(arg3: undefined): undefined;
function someFunction(arg3: string | number): string;
function someFunction(arg3: string | number | undefined) {
return typeof arg3 == "undefined"
? undefined
: (arg2 && !Number.isNaN(Number(arg3))) || typeof arg3 == "number"
? arg1 + "something"
: arg3;
}
}
- dzharii/awesome-typescript A collection of awesome TypeScript resources for client-side and server-side development. Write your awesome JavaScript in TypeScript
- Announcing TypeScript 3.4 RC
- Propagated generic type arguments,
globalThis
,const
assertions (let x = 10 as const
) ,--incremental flag
- Propagated generic type arguments,
- From [BUG] union extend behavior not the same into a type
- conditional-types-in-typescript
- TypeScript 2.8: Conditional Types
-
Since
NonNullable<T>
checks a naked type parameter, it is distributed over a union typeA | B
. This means thatNonNullable<A | B>
is resolved asNonNullable<A> | NonNullable<B>
-
- @meta-utils/types-A package containing useful TypeScript types
- types used in aurelia
- simplytyped - Yet another typing library. This differs by aiming to be less experimental than others, driven by industry use cases.
- typepark - a new type collection offering tuple manipulation and
Pipe
- type-zoo - A menagerie of useful type operators for TypeScript
- utility-types - Utility Types for TypeScript (provide compatibility with Flow's Utility Types)
- ts-essentials - All essential TypeScript types in one place
- typescript-conditional-types - Helpers for typescript generic types
- ts-types-utils - Type utilities for typescript
- typescript-test-utils - Helper types for testing your package exported types
- @ktb/type-compare - A collection of comparison utility types for Typescript.
- rex-tils - Type safe utils for redux actions, epics, effects, react/preact default props, various type guards and TypeScript utils, React util components
- runtypes-Runtime validation for static types
- @cadre/ts-utils - A set of utilities shared between my projects
- alcalzone-shared - A set of utilities shared between my projects
- mocoolka-css - Mocoolka-css define Css Component with orginal css property and predefine property.
- csx - Utility functions for TypeStyle
- csstype - Strict TypeScript and Flow types for style based on MDN data
- @johanneslumpe/css-types -TypeScript CSS types and value helpers generated from MDN data
- uom-ts - Units of measure type safety, with no runtime overhead, supporting multiplication and division
type LiteralUnion<T extends U, U = string> = T | (U & { zz_IGNORE_ME?: never })
Example:
type Color = LiteralUnion<'red' | 'black'>
var c: Color = 'red' // Has intellisense
var d: Color = 'any-string' // Any string is OK
var d: Color = { zz_IGNORE_ME: '' } // { zz_IGNORE_ME } placeholder is at the bottom of intellisense list and errors because of never
type N = LiteralUnion<1 | 2, number> // Works with numbers too