I've come across an issue when trying to use Exact
. I've got a hierarchy of types, and i'm also trying to implement classes based on those types. Here's the example (also here's the playground link https://tsplay.dev/w8xKdw) that is about as small as I can make it.
type SmallType = {
one: string;
}
type IntermediateType = {
inter_a?: SmallType;
}
type FinalType = {
final_a?: IntermediateType;
}
class SmallClass implements Exact<SmallType, SmallClass> {
one: string;
constructor(one: string){
this.one = one;
}
}
class IntermediateClass implements Exact<IntermediateType, IntermediateClass> {
inter_a?: SmallClass;
}
class FinalClass implements Exact<FinalType, FinalClass> {
final_a?: IntermediateClass; // <-- this field generates a typescript error
}
The bug is right there with FinalClass
. If I use exact, I get a type error:
Property 'final_a' in type 'FinalClass' is not assignable to the same property in base type 'ExactObject<FinalType, FinalClass>'.
Type 'IntermediateClass | undefined' is not assignable to type 'ExactObject<IntermediateType, IntermediateClass | undefined> | undefined'.
Type 'IntermediateClass' is not assignable to type 'ExactObject<IntermediateType, IntermediateClass | undefined>'.
Type 'IntermediateClass' is not assignable to type '{ inter_a?: ExactObject<SmallType, never> | undefined; }'.
Types of property 'inter_a' are incompatible.
Type 'SmallClass | undefined' is not assignable to type 'ExactObject<SmallType, never> | undefined'.
Type 'SmallClass' is not assignable to type 'ExactObject<SmallType, never>'.
Type 'SmallClass' is not assignable to type 'Record<string | number | symbol, never>'.
Index signature for type 'string' is missing in type 'SmallClass'.
Should I be able to use Exact
like this? Some of the types are coming from a code generator, so that's why i'm trying to make sure my classes match.
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too