Types I'm tired of rewriting.
npm install useful-typescript-typesuseful-typescript-types Types I'm tired of rewriting.
- Utility Types
- ObjectPath
- Example
- ObjectPathContainsKey
- Example
- ValueAtObjectPath
- Example
- DeepPartial
- ArrayItem
- Tuple
- Example
- VariadicTuple
- Example
- Nullable
- RequiredProperties
- OmitFunctionKeys
- PickKeysByValue
- PickFunctionKeys
- PickObjectKeys
- PickArrayKeys
- PickStringKeys
- PickNumberKeys
- Mutable
- Immutable
- Syntactic Sugar Types
- Primitives
- Json
- JsonObject
- JsonArray
- Json Value
- Comparables
- Callback
- Example
- CallbackWithArgs
- Example
- Result
- Example
- Example
- Action
- Example
Get the path keys of an object as string literals.
#### Example
``typescript
const myObj = {
foo: {
bar: "hi",
baz: "hello",
},
};
type MyObjPath = ObjectPath
`
Get the path keys of an object that contains a certain key.
#### Example
`typescript
const myObj = {
foo: {
bar: {
baz: "hi",
},
},
};
type findBazPath = ObjectPathContainsKey
`
Get the value of an object at a certain path (using dot notation)
#### Example
`typescript
const myObj = {
foo: {
bar: {
baz: "hi",
},
},
} as const;
type baz = ValueAtPath
`
Make all properties and nested properties of an object optional.
Get the type of an array item.
Define a tuple with exactly 2 elements of types T and N.
#### Example
`typescript`
const tuple: Tuple
Define a tuple with a variable number of elements.
#### Example
`typescript`
const vTuple: VariadicTuple
Define a type that can be null or of type T.
Make all properties of an object required, removing optional modifiers.
Omit keys of an object that have function values.
Pick keys of an object that have Type values
`typescript
const obj = { foo: "bar", baz: 42 };
type MyKeys = PickKeysByValue
`
#### PickFunctionKeys
Pick keys of an object that have function values.
#### PickObjectKeys
Pick keys of an object that have object values.
#### PickArrayKeys
Pick keys of an object that have array values.
#### PickStringKeys
Pick keys of an object that have string values.
#### PickNumberKeys
Pick keys of an object that have number values.
Remove readonly modifier from all properties of an object
Make all properties of an object readonly
Primitive types. Builds on top of Comparables.
Json types.
#### JsonObject
A Json object consists of a JsonObject or JsonArray, which in turn consist of JsonValues.
#### JsonArray
A Json array consists of JsonValues.
#### Json Value
A Json value can be a string, number, boolean, null, JsonObject, or JsonArray.
Primitive types that can be compared, including number, string, and BigInteger.
A function that returns type T or void.
#### Example
`typescript`
const myCallback: Callback
A function that returns type T or void and takes arguments of type Args.
#### Example
`typescript`
const myCallback: CallbackWithArgs
"foo";
A result type that can be either a success or an error.
#### Example
`typescript`
const myResult: Result
const myResult: Result
#### Example
`typescript`
const myDict: Dictionary
For state management systems like Redux, representing an action with a type and payload.
#### Example
`typescript``
type Actions = Action<"INCREMENT", number> | Action<"DECREMENT", number>;