I have a type in typescript, that is an object, for which all of the properties should be of type number
. Based on this type, I would like to create various interfaces, which are more concrete then the original type, and pass them as generic parameters to a class, which excepts a generic that extends my basic type, but I always get the following typescript error:
Index signature for type 'xxx' is missing in type 'yyy'
Is something similar to what I want to do is possible in typescript? The best I was able to achieve, is telling my moreConcrete
interface, that it extends the basic
type, this way, the error goes away, but I lose autocompletion and other intellisense features when trying to use the interface.
Here's a fiddle with an example: Fiddle
And here's the code in the fiddle:
type basic = {
[key: string]: number
}
class A<TInput extends basic> {
}
interface moreConcrete {
a: number,
b: number
}
const test = new A<moreConcrete>(); // this does not work like this
interface otherMoreConcrete extends basic {
a: number,
b: number
}
const test2 = new A<otherMoreConcrete>(); // this does not give any errors
const typeTest: keyof otherMoreConcrete = 'as'; // this accepts as as a key of otherMoreConcrete, because of the extension to `basic`, this should be an error