Comments (3)
+1 @alexeyraspopov Any idea
from dataclass.
I'm trying to figure out a way to define some sort of runtime value validation but it should be a complementary API. Right now you can write some sort of custom validation for cases where you need it:
class User extends Data {
name: string = 'Anon';
age: number = 0;
static from(values) {
let name: string = values.name ?? 'Anon'
if (isNaN(values.age)) {
throw new Error('age is missing')
}
let age: number = values.age;
return User.create({ name, age })
}
}
from dataclass.
Maybe we could implement a validate method that does nothing on the parent class, that you can override on the child class if you need validation and throw
from dataclass.
Related Issues (15)
- [Error] Class constructor Record cannot be invoked without 'new' HOT 5
- Object prototype undefinded HOT 7
- Nested dataclasses are either not supported or undocumented HOT 1
- Document parameter properties as a partial alternative HOT 1
- Attemp to instantiate a class raises "TypeError: Cannot redefine property" on NodeJS 14.17.6 HOT 2
- `create` makes all properties optional HOT 3
- Dataclass doesn't work in Jupyter notebook HOT 3
- TypeError: Class constructor Data cannot be invoked without 'new' HOT 3
- Create data class without default values HOT 2
- copy() method makes plain Object (TypeScript) HOT 1
- can you publish a new version? HOT 2
- Support for embedded class or object HOT 5
- Formal integration with yarn HOT 2
- Is it possible to define compulsory fields (without defaults)? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dataclass.