Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save davidystephenson/72da4bc188f2f5f276d511c3d1cbfd24 to your computer and use it in GitHub Desktop.
Save davidystephenson/72da4bc188f2f5f276d511c3d1cbfd24 to your computer and use it in GitHub Desktop.
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