Closed niobos closed 1 year ago
Update: This does work with dataclass@2.0.0, but fails with dataclass@2.1.0 and 2.1.1
@niobos, greetings!
Looking at the code example and error message, I feel like the root cause is lack of default values in class declaration. See Optional keys and code compilation caveat guide. I never used tslab and I am not sure what TS config it uses, but I assume your case can be solved by adding some default values to the properties:
import { Data } from "dataclass";
class Foo extends Data {
name: string | null = null;
value: number | null = null;
}
let a = Foo.create({name: "test", value: 42})
Hi @alexeyraspopov,
Thank you for getting back to me.
Your guess is correct, adding | null = null
does make the error disappear. Using ?:
does not solve the issue.
Thank you again for your time
Hi,
First of all, thank you for your time and effort into making this project. I really appreciate that I'm able to stand on the shoulders of giants.
I'm trying to use Dataclass in a Jupyter/tslab notebook, but it fails:
This gives the following output:
I don't think this is an issue with
dataclass
itself, but I this seems like the most logical place to start. Feel free to point me to a better place to get help.Regards,