Giter Site home page Giter Site logo

Comments (13)

cloud-walker avatar cloud-walker commented on June 11, 2024 2

oh I see, AFAIK tuple exists in TS only on the type level, so they are arrays anyway

from faker.

matthewmayer avatar matthewmayer commented on June 11, 2024 1

faker.helpers.arrayElements() can work with any JavaScript array though, it's not necessary typed.

from faker.

matthewmayer avatar matthewmayer commented on June 11, 2024 1

I mean tuples don't exist in JavaScript so would need to ensure this doesn't break anything for regular JavaScript arrays.

from faker.

ST-DDT avatar ST-DDT commented on June 11, 2024

I have a rough estimate on what you are asking, I'm just now sure how to properly model it with TS.
Especially in combination with the dynamic length ranges.
Could you please explain how you would handle that?

Also could you explain why you want this change? As that helps us understand your request better.

from faker.

cloud-walker avatar cloud-walker commented on June 11, 2024

Hi @ST-DDT the TS in this case is not the easiest in my experience, I've already done experiments on my codebase, and the problem to solve is similar to the one solved on remeda codebase for the hasAtLeast function.

In our case the count maybe undefined or number or {min: number; max: number} so it's a bit more challenging.

Also could you explain why you want this change? As that helps us understand your request better.

Using the noUncheckedIndexedAccess option the destructuring of the array generated by arrayElements becomes less ergonomic as the elements would be of type T | undefined

import {faker} from '@faker-js/faker'

const langsPool = ['en', 'it', 'fr', 'es'] as const

const [langA, langB] = faker.arrayElements(langsPool, 2)

// referencing langA and langB later on is not safe when in reality it should be

from faker.

ST-DDT avatar ST-DDT commented on June 11, 2024

We could limit the feature to fixed size arrays at first, so we split the method into separate signatures and add the feature only to one of them.

from faker.

ST-DDT avatar ST-DDT commented on June 11, 2024

One of the problems I see is that removing elements from the resulting array invalidates it's type then.

from faker.

cloud-walker avatar cloud-walker commented on June 11, 2024

I think that the helpers can continue to be dynamic as it is, we just need to handle a more complex type signature, I can try to make a PR, the same stuff apply to other helpers, like:

  1. multiple()
  2. uniqueArray()

I can obviously start small experimenting with arrayElements first

from faker.

cloud-walker avatar cloud-walker commented on June 11, 2024

@matthewmayer what do you mean? Of course it works with any array 🤔

from faker.

Related Issues (20)

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.