-
Notifications
You must be signed in to change notification settings - Fork 0
Common Built‐in and Utility Types
Jorge Castro edited this page Nov 10, 2025
·
1 revision
type Route = { path: string; name: string; component: string };
const routes: Record<string, Route> = {
home: { path: '/', name: 'Home', component: 'HomeComponent' },
about: { path: '/about', name: 'About', component: 'AboutComponent' },
contact: { path: '/contact', name: 'Contact', component: 'ContactComponent' },
}type Product = { id: number; name: string; price: number; description?: string; };
declare function createProductOnAmazon(product: Required<Product>): void;type Product = { id: number; name: string; price: number; description?: string; };
declare function updateProduct(product: Partial<Product>): void;type Role = 'admin' | 'userPremium' | 'userBasic' | 'userTrial' | 'guest';
type UserRoles = Exclude<Role, 'guest'>;type State =
| { status: "loading" }
| { status: "success"; data: Array<{ id: number; name: string }> }
| { status: "error"; error: Error };
type SuccessEvent = Extract<State, { status: "success" }>;type Product = { id: number; name: string; amazonUrl: string; mercadoLibreUrl: string; };
declare function getProductUrlsById(id: number): Pick<Product, "amazonUrl" | "mercadoLibreUrl">;type Product = { id: number; name: string; price: number; description?: string; };
type NewProduct = Omit<Product, "id">;const getProductById = (id: number) => [
{ id: 1, name: "Product 1", price: 100 },
{ id: 2, name: "Product 2", price: 200 },
].find(product => product.id === id);
type Product = ReturnType<typeof getProductById>;declare function showCordOnMap(x: number, y: number, z: number): void;
type Cord = Parameters<typeof showCordOnMap>;type Product = { id: number; name: string; price: number };
const getProducts: () => Promise<Product[]> = async () => [
{ id: 1, name: "Product 1", price: 100 },
{ id: 2, name: "Product 2", price: 200 },
];const getProductById = async (id: number) => [
{ id: 1, name: "Product 1", price: 100 },
{ id: 2, name: "Product 2", price: 200 },
].find(product => product.id === id);
type Product = Awaited<ReturnType<typeof getProductById>>;const getProductById = (id: number) => [
{ id: 1, name: "Product 1", price: 100 },
{ id: 2, name: "Product 2", price: 200 },
].find(product => product.id === id);
type Product = NonNullable<ReturnType<typeof getProductById>>;- Sync-Obsidian-with-GitHub-on-iOS
- Obsidian-community-plugins
- Optimizing-Novel-Word-Count-Plugin-for-Git-Users
- What is TypeScript, and why you should use it
- Quick setup
- Inference and type annotations
- Fundamental Types
- Object Types
- Union Types
- Type Aliases and Interfaces
- Type Assertions
- Literal Types
- null and undefined
- Narrowing
- Creating Types from Types
- Common Built‐in and Utility Types
- tsc CLI ‐ (The Compiler)
- Avoid using Object or {}
- Ignoring TypeScript errors
- TypeScript resources