Coggle requires JavaScript to display documents.
const mergedObj = merge( { name: 'Max', hobbies: ['Sports'] }, { age: 30 });
function merge(objA: object, objB: object) { return { ...objA, ...objB }; }
object
console.log(mergedObj.name);
Property 'name' does not exist on type '{}'
name
function merge<T, U>(objA: T, objB: U) { return { ...objA, ...objB }; }
T & U
const mergedObj: { name: string; hobbies: string[]; } & { age: number; }
const mergedObj = merge( { name: 'Max', hobbies: ['Sports']}, 30 );
objA
{ "name": "Max", "hobbies": [ "Sports" ] }
30
T
U
objects
function merge<T extends object, U extends object>(objA: T, objB: U) { ... }
let list: number[] = [1, 2, 3];
let list: Array<number> = [1, 2, 3];
const promise: Promise<string> = new Promise((resolve, reject) => { setTimout(() => { resolve('This is done!'); }, 2000); });
function identity(arg: number): number { return arg; }
function identity(arg: any): any { return arg; }
Type
function identity<Type>(arg: Type): Type { return arg; }
let output = identity<string>("myString");
<>
let output = identity("myString");
output
string