Created
September 6, 2025 16:16
-
-
Save davidystephenson/d42370adb6bfe6e15da002c1c9c6b0d8 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 input1: Input<boolean> = true | |
const input2: Input<string[]> = true | |
type Collection <T> = [T, T, T] | |
const stringCollection: Collection<string> = ['a', 'b', 'c'] | |
const numberCollection: Collection<number> = ['a', 2, 3] | |
interface Vehicle <Cargo> { | |
position: number | |
speed: number | |
seats: number | |
wheels: number | |
cargo: Cargo | |
} | |
type DriverlessVehicle = Omit<Vehicle<undefined>, 'seats' | 'wheels'> | |
const breadVan: Vehicle<{ white: number, brown: number }> = { | |
position: 0, | |
speed: 50, | |
seats: 2, | |
wheels: 4, | |
cargo: { white: 10, brown: 5 } | |
} | |
const passengerVan: Vehicle<string[]> = { | |
position: 0, | |
speed: 60, | |
seats: 20, | |
wheels: 4, | |
cargo: ['Dorothy', 'Zelda', 'Tallulah'] | |
} | |
function pilot <Cargo> (vehicle: Vehicle<Cargo>, pilotName: string): Cargo { | |
console.log(pilotName, 'is piloting the vehicle') | |
return vehicle.cargo | |
} | |
type PilotResult = ReturnType<typeof pilot> | |
const result = pilot(passengerVan, 'David') | |
const totalPassengers = 1 + result.length |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment