aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorST-DDT <[email protected]>2022-04-29 12:39:55 +0200
committerGitHub <[email protected]>2022-04-29 12:39:55 +0200
commit8ce7f3ea8b1daa76097af40693d67a61e2dfbef5 (patch)
tree6e974eefdb1f4a10041ecb257a7d14ef92175772
parent98b6289bb94fee4cba9e5e605ea76e55a1d63128 (diff)
downloadfaker-8ce7f3ea8b1daa76097af40693d67a61e2dfbef5.tar.xz
faker-8ce7f3ea8b1daa76097af40693d67a61e2dfbef5.zip
chore: fix any warnings in image module (#886)
-rw-r--r--src/image.ts3
-rw-r--r--src/image_providers/lorempixel.ts3
-rw-r--r--src/utils/types.ts17
3 files changed, 21 insertions, 2 deletions
diff --git a/src/image.ts b/src/image.ts
index 8aeab602..9fe7f603 100644
--- a/src/image.ts
+++ b/src/image.ts
@@ -2,6 +2,7 @@ import type { Faker } from '.';
import { LoremPicsum } from './image_providers/lorempicsum';
import { Lorempixel } from './image_providers/lorempixel';
import { Unsplash } from './image_providers/unsplash';
+import type { MethodsOf } from './utils/types';
/**
* Module to generate placeholder images.
@@ -40,7 +41,7 @@ export class Image {
* faker.image.image(1234, 2345, true) // 'http://loremflickr.com/1234/2345/nature?56789'
*/
image(width?: number, height?: number, randomize?: boolean): string {
- const categories = [
+ const categories: MethodsOf<Image, Image['image']> = [
'abstract',
'animals',
'business',
diff --git a/src/image_providers/lorempixel.ts b/src/image_providers/lorempixel.ts
index 914f1066..50e48ede 100644
--- a/src/image_providers/lorempixel.ts
+++ b/src/image_providers/lorempixel.ts
@@ -1,4 +1,5 @@
import type { Faker } from '..';
+import type { MethodsOf } from '../utils/types';
/**
* Module to generate links to random images on `https://lorempixel.com/`.
@@ -14,7 +15,7 @@ export class Lorempixel {
* @param randomize Whether to append a seed to the url. Defaults to `false`.
*/
image(width?: number, height?: number, randomize?: boolean): string {
- const categories = [
+ const categories: MethodsOf<Lorempixel, Lorempixel['image']> = [
'abstract',
'animals',
'business',
diff --git a/src/utils/types.ts b/src/utils/types.ts
new file mode 100644
index 00000000..705d02d1
--- /dev/null
+++ b/src/utils/types.ts
@@ -0,0 +1,17 @@
+/**
+ * Type that represents a single method/function name of the given type.
+ */
+export type MethodOf<
+ ObjectType,
+ Signature extends (...args) => unknown = (...args) => unknown
+> = {
+ [Key in keyof ObjectType]: ObjectType[Key] extends Signature ? Key : never;
+}[keyof ObjectType];
+
+/**
+ * Type that represents all method/function names of the given type.
+ */
+export type MethodsOf<
+ ObjectType,
+ Signature extends (...args) => unknown = (...args) => unknown
+> = ReadonlyArray<MethodOf<ObjectType, Signature>>;