From d31c635e6efc4013ea44a6676f832091c1763050 Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Fri, 21 Jun 2024 11:49:51 +0200 Subject: chore: remove arrayElement(s) js only error (#2958) --- docs/guide/upgrading.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'docs') diff --git a/docs/guide/upgrading.md b/docs/guide/upgrading.md index 9797a48c..beccc457 100644 --- a/docs/guide/upgrading.md +++ b/docs/guide/upgrading.md @@ -349,6 +349,24 @@ const city = enforcer.enforce(faker.location.city, { `enforce-unique` does not directly support the `store` option previously available in `faker.helpers.unique`. If you were previously using this parameter, check the [documentation](https://www.npmjs.com/package/enforce-unique). If you need to reset the store, you can call the `reset()` method on the `UniqueEnforcer` instance. ::: +#### `faker.helpers.arrayElement` and `faker.helpers.arrayElements` + +The following only affects usage in Javascript, as in Typescript this usage would already throw a compile-time error. + +Previously, the `arrayElement` and `arrayElements` methods would throw a dedicated error, when called without arguments. + +```ts +faker.helpers.arrayElement(undefined); // FakerError: Calling `faker.helpers.arrayElement()` without arguments is no longer supported. +``` + +Now, it throws a JS native error: + +```ts +faker.helpers.arrayElement(undefined); // TypeError: Cannot read properties of undefined (reading 'length') +``` + +Calling the methods with an empty array instead still behaves as before. + ### Image Module Removed deprecated image methods -- cgit v1.2.3