I have the following code, and I receive the following error
Type 'T' does not satisfy the constraint 'string | number | symbol'. Type 'T' is not assignable to type 'symbol'.
I would like to know how to fix the generic so I can pass a union Record
export type Project<T> = Readonly<{
dirs: Record<T, string>
setup: () => Promise<string>
}>
type Dirs = 'a' | 'b' | 'c'
type Start = Project<Dirs>
If you need this constraint, then you simply have to add it. Maybe you could even make it more restrictive (removing symbol, for example):
export type Project<T extends string | number | symbol> = Readonly<{
dirs: Record<T, string>
setup: () => Promise<string>
}>
type Dirs = 'a' | 'b' | 'c'
type Start = Project<Dirs>
Please also note that I don't understand what you want to do with Record<T, string>. Record is used to only keep some keys in a given object type. Do you actually simply mean dirs: T? If so, you can do it like this:
export type Project<T extends string> = Readonly<{
dirs: T
setup: () => Promise<string>
}>
type Dirs = 'a' | 'b' | 'c'
type Start = Project<Dirs>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With