Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added fixes for new Array() #14

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/slimy-kiwis-wonder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@total-typescript/ts-reset": minor
---

Added a new rule for handling new Array() and Array(), making them return `unknown[]` instead of `any[]`.
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@
"import": "./dist/utils.mjs",
"types": "./dist/utils.d.ts",
"default": "./dist/utils.js"
},
"./array-constructor": {
"import": "./dist/array-constructor.mjs",
"types": "./dist/array-constructor.d.ts",
"default": "./dist/array-constructor.js"
}
},
"keywords": [],
Expand Down
4 changes: 4 additions & 0 deletions src/entrypoints/array-constructor.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
interface ArrayConstructor {
new (arrayLength?: number): unknown[];
(arrayLength?: number): unknown[];
}
1 change: 1 addition & 0 deletions src/entrypoints/recommended.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
/// <reference path="json-parse.d.ts" />
/// <reference path="array-includes.d.ts" />
/// <reference path="set-has.d.ts" />
/// <reference path="array-constructor.d.ts" />
13 changes: 13 additions & 0 deletions src/tests/array-constructor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { doNotExecute, Equal, Expect } from "./utils";

doNotExecute(() => {
const arr = new Array(1);

type tests = [Expect<Equal<typeof arr, unknown[]>>];
});

doNotExecute(() => {
const arr = Array(1);

type tests = [Expect<Equal<typeof arr, unknown[]>>];
});