Skip to main content

add

add() function

Adds two values.

Signature:
declare function add<A extends number | Promise<number>, B extends number | Promise<number>>(a: A, b: B): ReturnAddType<number | Promise<number>, A, B>;

declare function add<A extends string | Promise<string>, B extends string | Promise<string>>(a: A, b: B): ReturnAddType<string | Promise<string>, A, B>;

declare function add<A extends number | Promise<number>, B extends number | Promise<number>>(a: A): (b: B) => ReturnAddType<number | Promise<number>, A, B>;

declare function add<A extends string | Promise<string>, B extends string | Promise<string>>(a: A): (b: B) => ReturnAddType<string | Promise<string>, A, B>;

Example

add(1, 2); // 3
await add(1, Promise.resolve(2)); // 3
await add(Promise.resolve(1), 2); // 3
await add(Promise.resolve(1), Promise.resolve(2)); // 3

add('a', 'b'); // 'ab'
await add('a', Promise.resolve('b')); // 'ab'
await add(Promise.resolve('a'), 'b'); // 'ab'
await add(Promise.resolve('a'), Promise.resolve('b')); // 'ab'

Open Source Code