Closed
Description
This is new as of 3.5.1, there was no error in 3.4.5.
Error message:
TS2536: Type 'string' cannot be used to index type 'T'
Obviously wrong, since T
is defined as Record<string, any>
.
function isString (thing: unknown): thing is string {
return typeof thing === 'string';
}
function clone<T extends Record<string, any>>(obj: T): T {
const objectClone = {} as T;
for (const prop of Reflect.ownKeys(obj).filter(isString)) {
objectClone[prop] = obj[prop];
}
return objectClone;
}
Playground Link — It will not show an error until the Playground uses the new TS 3.5.x