Comments (3)
I do eventually want to support custom types. For now, I will probably just add SetOf, MapOf.
I will think on the API for a custom type checker afterwards. I could just expose Validator
and ValidatorResult
which I use internally, but they are a little confusing, and usually overkill for simple types.
from decoratethis.
I think this will get us by.
const ImmutableMap = KeyedCollection(Immutable.Map, map => map.toObject());
const ImmutableListOf = TypedCollection(Immutable.List, list => list.toArray());
class T {
@param(ImmutableMap({key: String, val: String}))
doThing() {
}
@param(ImmutableListOf(Number))
doOtherThing() {
}
}
KeyedCollection
takes two arguments, a constructor/class and a transformation function. It returns a function which takes a type.
- The transformation function must return a plain Object
TypedCollection
takes two arguments, a constructor/class and a transformation function. It returns a function which takes a type.
- The transformation function must return either an Array or an Object.
- The returned value will be iterated over with a
for...of
loop - Each member of the value will be validated against the type
@callumlocke any comments?
from decoratethis.
looks great
from decoratethis.
Related Issues (11)
- Generate documentations through `param` and `return`
- Instance specific HOT 2
- import examples seem to be wrong? HOT 1
- Build this before uploading HOT 1
- Type-checking for promise fulfillment values HOT 3
- Decorator for type-checking 'rest parameters' HOT 1
- @returns(Self) ? HOT 6
- Multiple arguments in a single decorator HOT 1
- Optional function arguments support HOT 1
- Multi args @param validations HOT 1
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 decoratethis.