Giter Club home page Giter Club logo

Comments (4)

rodmax avatar rodmax commented on May 18, 2024

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.

rodmax avatar rodmax commented on May 18, 2024

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.

rodmax avatar rodmax commented on May 18, 2024

@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.

JoseLion avatar JoseLion commented on May 18, 2024

@rodmax awesome! Yep, I think that solves the issue. Thanks a lot for looking into it 🎉

from factory-t.

Related Issues (12)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.