In Typescript (5.0+), how can I achieve the following:
export interface MyFirstInterface {
fieldCanOnlyBeString: string,
fieldCanOnlyBeNumber: number,
[unknownFieldName:string]: MyCustomInterface
}
Whenever I declare a variable with the MyFirstInterface
type, I would like one field to be a number, one is a string and the rest be MyCustomInterface
How can I declare this in TS, given the classic [key:string]: string
would mean every string key-type must be a string type?
What is the correct way to realise the idea of "specific field names have a specific type, all the other fields must be this other type" in Typescript?
I have tried with a couple of generics with various types, unions, never's etc... but no other solutions really answered my problem in straightforward manner.