diff --git a/week-7/typescript-assignment/index.ts b/week-7/typescript-assignment/index.ts new file mode 100644 index 000000000..0ec42a094 --- /dev/null +++ b/week-7/typescript-assignment/index.ts @@ -0,0 +1,12 @@ +type Pair = [T, T]; + +function swapPair(a: T, b: T): Pair { + return [b, a]; +} + +const output1: Pair = swapPair(1, 2); +const output2: Pair = swapPair(true, false); +const output3: Pair = swapPair("c", "a"); +const output4: Pair = swapPair("c", 1); // error since mismatch types + +console.log(output4);