Aug 22, 2024
number
:
function getFirstElement(arr: number[]): number {
return arr[0];
}
any[]
, return type is any
, which is not useful.function getFirstElement<T>(arr: T[]): T {
return arr[0];
}
number
.string
.document.querySelector
and Array.prototype.map()
.const myMap = new Map<string, number>();
const nestedMap = new Map<string, Map<string, number>>();
type ApiResponse<T> = {
data: T;
isError: boolean;
};
type UserResponse = ApiResponse<{ name: string; age: number }>;
type ApiResponse<T = { status: number }> = {...};
type ApiResponse<T extends object> = {...};