Skip to content

Instantly share code, notes, and snippets.

@jasonbyrne
Created Apr 14, 2022
Embed
What would you like to do?
Get and Change
class FoodItem {
constructor(private opts: FoodProperties) {}
public get<T extends keyof FoodProperties>(property: T): FoodProperties[T] {
return this.opts[property];
}
public change<T extends keyof FoodProperties>(
property: T,
value: FoodProperties[T]
) {
this.opts[property] = value;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment