Created
May 11, 2025 20:56
-
-
Save ivan/2b224023b97d78ecc3050dae79e9fbef to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sum<T extends number | bigint>(a: T, b: T): T extends number ? number : bigint { | |
// @ts-expect-error | |
return a + b; | |
} | |
function sumo(a: number, b: number): number; | |
function sumo(a: bigint, b: bigint): bigint; | |
function sumo(a: number | bigint, b: number | bigint): number | bigint { | |
// @ts-expect-error | |
return a + b; | |
} | |
console.log(sum(100, 200)); | |
console.log(sum(100n, 200n)); | |
console.log(sum(100, 300)); | |
let n: number | bigint = 400n; | |
if (Math.random() <= 0.5) { | |
n = 400; | |
} | |
console.log(sum(n, 800n)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment