Skip to content

Commit f789ce5

Browse files
ajafffsindresorhus
authored andcommitted
TypeScript - Add overload for ReadonlyArray (#7)
1 parent d437961 commit f789ce5

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ arrify(undefined);
2626
declare function arrify(value: null | undefined): [];
2727
declare function arrify(value: string): [string];
2828
declare function arrify<ValueType>(value: ValueType[]): ValueType[];
29+
// TODO: Use 'readonly ValueType[]' in the next major version
30+
declare function arrify<ValueType>(value: ReadonlyArray<ValueType>): ReadonlyArray<ValueType>;
2931
declare function arrify<ValueType>(value: Iterable<ValueType>): ValueType[];
3032
declare function arrify<ValueType>(value: ValueType): [ValueType];
3133

index.test-d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {expectType} from 'tsd';
1+
import {expectType, expectError} from 'tsd';
22
import arrify = require('.');
33

44
expectType<[]>(arrify(null));
@@ -12,3 +12,4 @@ expectType<([string | number, string | number])[]>(
1212
arrify(new Map<string | number, string | number>([[1, 2], ['a', 'b']]))
1313
);
1414
expectType<number[]>(arrify(new Set([1, 2])));
15+
expectError(arrify(['🦄'] as const).push(''));

0 commit comments

Comments
 (0)