In TypeScript, function Array.Prototype.includes requires me to pass in the same type as in the original array. But I'm thinking isn't the whole point of using includes to find out if a key of arbitrary string type exists in an array with known type?
Consider code below:
type CONFIG_MODEL = {
URL: string;
Protocol: string;
Port: number;
Encrypted: boolean;
}
const ALLOWED_KEYS: (keyof CONFIG_MODEL)[] = ['URL', 'Protocol'];
function setup(configs: { [key: string]: string }) {
Object.keys(configs).forEach(configKey => {
if (ALLOWED_KEYS.includes(configKey)) {
// do something
}
})
}
TypeScript throws me an error when using includes, stating:
Argument of type 'string' is not assignable to parameter of type 'keyof CONFIG_MODEL'
Thanks!