Comments (4)
Hi @JoseLion. Thank You for feedback.
First. Yes. It makes sense for this library because of one of the base requirement: strongly follow to target type
I quickly look into implementation and see that approach for optional already exists:
import { factoryT, FactoryT, fields } from 'factory-t';
interface WithOptional {
password?: string;
}
const factory = factoryT<WithOptional>({
password: fields.optional('default'),
});
BUT it is not working properly and just makes typing trick, not really makes field optional 😞
I believe it's needed to enhance fields.optional()
approach something like so:
const factory = factoryT<{key?: string}>({
key: fields.optional(fields.NOT_SET_VALUE)
// or
key: fields.optional(), // empty argument means that by default key is missing in generated item
key: undefined, // this last not appreciable due to not recognizes {key: string | undefined} with {key?: string}
})
console.log(factory.item())
// {} instead of {key: undefined}
console.log(factory.item({key: 'hello'}))
// {key: 'hello'}
I see some difficulties with typing of such an approach
I play with it evening and reply
from factory-t.
Usually, optional properties are not included in the factory definition
Oh, I missed one point provided by you 🤔. Right now I am not sure it may be implementable but I promise think about it too
from factory-t.
@JoseLion look at this solution: #111
Will it solve the problem?
if something confuses you or you have ideas for improvement(semantic/API), then do not hesitate, and let me now
from factory-t.
@rodmax awesome! Yep, I think that solves the issue. Thanks a lot for looking into it 🎉
from factory-t.
Related Issues (12)
- bug: handle case when object or array passed to key directly
- Dependency Dashboard
- chore: use sonar's code coverage instead of separate codecov service if possible HOT 1
- chore(ci): migrate from travis-ci.org to travis-ci.com
- bug: exception when call buildList({count: 0})
- Migrate from ts-lint to eslint
- Remove `makeSequenceFromEnum` helper due to wrong typing
- Add prettier
- Fix typo: makeSequen**s**eFromEnum -> makeSequen**c**eFromEnum
- README: add info about release workflow
- Action Required: Fix Renovate Configuration
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 factory-t.