Created
August 9, 2025 16:09
-
-
Save davidystephenson/72da4bc188f2f5f276d511c3d1cbfd24 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
type Input <T> = string | number | T | |
const i: Input<boolean> = false | |
const x: Input<number[]> = [1, 2, 3] | |
interface Guest { | |
name: string | |
email: string | |
age: number | |
} | |
type AgelessGuest = Omit<Guest, 'age' | 'name'> | |
interface Output <T extends keyof Guest> { | |
date: number | |
result: T | |
} | |
type DatelessOutput = Omit<Output<'email'>, 'date'> | |
const output1: Output<'name'> = { | |
date: 123, | |
result: 'name' | |
} | |
const output2: Output<'age'> = { | |
date: 345, | |
result: 'age' | |
} | |
class Container <T> { | |
items: T[] | |
constructor () { | |
this.items = [] | |
} | |
} | |
const stringContainer = new Container<string> | |
stringContainer.items.push('hello') | |
function labelItem <T extends object> (item: T) { | |
return { | |
label: 'ready', | |
item | |
} | |
} | |
type LabelResult = ReturnType<typeof labelItem> | |
const labeled = labelItem({ abc: 1 }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment