Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions week-7/typescript-assignment/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
type Pair<T> = [T, T];

function swapPair<T>(a: T, b: T): Pair<T> {
return [b, a];
}

const output1: Pair<number> = swapPair(1, 2);
const output2: Pair<boolean> = swapPair(true, false);
const output3: Pair<string> = swapPair("c", "a");
const output4: Pair<string> = swapPair("c", 1); // error since mismatch types

console.log(output4);