id
The identity function
export const id = <T>(x: T) => x;Example 1: Simultaneously declaring a type and instantiating a default value for this type
import { id } from "tsafe/id";
const defaultCat = {
name: "Felix",
gender: id<"male" | "female">("male"),
};
type Cat = typeof defaultCat;


Example 2: Instantiating an object of type T


Last updated
Was this helpful?