update I have included my current code to better illustrate the problem:
https://gist.github.com/LukasBombach/7bf255392074509147a250b448388518
Using TypeScript, I aim to define a generic that represents any plain object data structure
class MyClass<T extends {}> {
public vars: T;
constructor() {
this.vars = {};
}
}
which allows me to use it like this
interface MyType {
foo: string;
bar: number;
}
new MyClass<MyType>()
or like this
interface MyType {
baz: string;
boo: {
bam: Function;
bix: number;
};
}
new MyClass<MyType>()
However, the implementation I have shown above is not functioning as expected, and I am encountering this error:
class MyClass<T extends {}> {
public vars: T;
constructor() {
this.vars = {};
// ^^^^
}
}
Type '{}' is not assignable to type 'T'. '{}' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'.ts(2322)