I'm trying to extend existing interface:
type ColDef = { field: string; }
so that I will limit field values only to actual properties of specified type:
interface TypeSafeColDef<T> extends ColDef {
field: keyof T
}
but I'm getting:
Interface 'TypeSafeColDef' incorrectly extends interface 'ColDef'. Types of property 'field' are incompatible. Type 'keyof TRow | undefined' is not assignable to type 'string | undefined'. Type 'keyof TRow' is not assignable to type 'string | undefined'. Type 'string | number | symbol' is not assignable to type 'string | undefined'. Type 'number' is not assignable to type 'string | undefined'. Type 'keyof TRow' is not assignable to type 'string'. Type 'string | number | symbol' is not assignable to type 'string'. Type 'number' is not assignable to type 'string'
I've tried following constraint, but no success
type StringKey = { [key: string]: any }
interface TypeSageColDef<TRow extends StringKey>
extends { [key: string]: any }
behaves same asextends object
for some reason (not limiting keys to bestring
only). Real question is why do you needextends ColDef
? Do you have more properties in real example? - Aleksey L.