Is it possible to infer a const type from a Set?

Say I have const foo = new Set([1,2,3]) how can I infer the type of foo as const? For example, const bar = [...foo.keys()] as const is of type number[] instead of type 1 | 2 | 3.
4 Replies
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
benten
bentenOP3y ago
Hmm
const foo = new Set([1,2,3] as const)
class Hehe {
constructor(input: Set<unknown>){
this.foo = input
}
bar(Record<???, string>){
//...
}
}
const foo = new Set([1,2,3] as const)
class Hehe {
constructor(input: Set<unknown>){
this.foo = input
}
bar(Record<???, string>){
//...
}
}
How would I type this then If I wanted the type of Bar(paramater) to be 1|2|3 ? keyof typeof this.foo doesn't work
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
benten
bentenOP3y ago
beautiful thanks One more question - If I want to allow other values as the key, but still want autocomplete is that possible? something like T | string doesn't work never mind i got it
Want results from more Discord servers?
Add your server