For TypeScript users, an atom instance's template type (e.g. when using instance.template) is inferred to be an instance of the Zedux built-in AtomTemplate class. But if the instance was created from a custom class that extends AtomTemplate, the type information of that child class would be lost. For example:
class MyTemplate extends AtomTemplate {
public customMethod() {
// ... implemention ...
}
}
const myCustomTemplateAtom = new MyTemplate('myCustomTemplate', () => 'example state')
const instance = ecosystem.getInstance(myCustomTemplateAtom)
instance.template.customMethod() // actually works! But TS used to complain
Now TS doesn't complain; the type information of the instance's actual atom template is retained
Description
For TypeScript users, an atom instance's template type (e.g. when using
instance.template
) is inferred to be an instance of the Zedux built-inAtomTemplate
class. But if the instance was created from a custom class that extendsAtomTemplate
, the type information of that child class would be lost. For example:Now TS doesn't complain; the type information of the instance's actual atom template is retained