Comments (13)
oh I see, AFAIK tuple exists in TS only on the type level, so they are arrays anyway
from faker.
faker.helpers.arrayElements() can work with any JavaScript array though, it's not necessary typed.
from faker.
I mean tuples don't exist in JavaScript so would need to ensure this doesn't break anything for regular JavaScript arrays.
from faker.
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.
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.
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.
One of the problems I see is that removing elements from the resulting array invalidates it's type then.
from faker.
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:
multiple()
uniqueArray()
I can obviously start small experimenting with arrayElements first
from faker.
@matthewmayer what do you mean? Of course it works with any array 🤔
from faker.
Related Issues (20)
- Add support for generating Roman Numerals HOT 2
- Proposal: Use a single seed value per faker function invocation HOT 4
- Remove or move roadmap? HOT 9
- Proposal: Design for standalone module functions HOT 14
- Add vitest github actions reporter
- Introduce oneOf helpers function HOT 5
- Support `const` modifier on type parameters HOT 1
- Export the default randomizer HOT 1
- Improve DX for methods that use all memory HOT 7
- Create test to ensure the locale metadata are correctly filled
- Re-evaluate signature of faker.date.between(s)
- faker.helpers.objectKey returns wrong type HOT 3
- Discuss boundaries of type-less JavaScript support HOT 10
- Make separate export for simpleFaker HOT 8
- [ERROR] The entry point "mock/table.ts.timestamp-1710847630001.mjs" cannot be marked as external HOT 4
- [v9 MAINTENANCE] - Please Read
- Re-add simplified implementation of helpers.unique HOT 6
- Email addresses are unknown on fakerHE in Hebrew HOT 1
- Random CI test failure in date.birthdate for specific age 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 faker.