I just have a normal array.
.includes()These two things seem to be incompatible for some reason... How should I do this?
const x = ['a', 'b', 'c'] as const;
type somethingElse = typeof x[number]; // 'a' | 'b' | 'c'
x.includes('foo' as string); // string not assignable to 'a' | 'b' | 'c'
ts playground
You can cast x to a string[] for the purposes of searching it.
const x = ['a', 'b', 'c'] as const;
type somethingElse = typeof x[number]; // 'a' | 'b' | 'c'
(x as readonly string[]).includes('foo'); // false
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