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

fix: filter error with as const unions #201

Merged
merged 11 commits into from
Aug 24, 2024
Merged
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
7 changes: 7 additions & 0 deletions .changeset/metal-moose-march.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@total-typescript/ts-reset": patch
---

@author: none23

Fixed a bug where running .filter on a union of arrays would not work.
2 changes: 0 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
with:
version: 9
- uses: actions/setup-node@v3
with:
node-version: 20.x
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
"prettier": "^3.2.5",
"tsx": "^3.14.0",
"turbo": "^1.13.3",
"typescript": "^5.4.5"
"typescript": "^5.5.4"
},
"prettier": {
"arrowParens": "always",
Expand All @@ -118,5 +118,6 @@
"singleQuote": false,
"tabWidth": 2,
"useTabs": false
}
},
"packageManager": "[email protected]+sha512.faf344af2d6ca65c4c5c8c2224ea77a81a5e8859cbc4e06b1511ddce2f0151512431dd19e6aff31f2c6a8f5f2aced9bd2273e1fed7dd4de1868984059d2c4247"
}
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions src/entrypoints/filter-boolean.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
/// <reference path="utils.d.ts" />

interface Array<T> {
filter(predicate: BooleanConstructor, thisArg?: any): TSReset.NonFalsy<T>[];
filter<S extends T>(
predicate: BooleanConstructor,
thisArg?: any,
): TSReset.NonFalsy<S>[];
}

interface ReadonlyArray<T> {
filter(predicate: BooleanConstructor, thisArg?: any): TSReset.NonFalsy<T>[];
filter<S extends T>(
predicate: BooleanConstructor,
thisArg?: any,
): TSReset.NonFalsy<S>[];
}
12 changes: 12 additions & 0 deletions src/tests/array-index-of.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ doNotExecute(async () => {
);
});

doNotExecute(() => {
const arr: string[] | number[] = {} as any;

const result = arr.indexOf("abc");
});

// lastIndexOf

doNotExecute(async () => {
Expand Down Expand Up @@ -131,3 +137,9 @@ doNotExecute(async () => {
true,
);
});

doNotExecute(() => {
const arr: string[] | number[] = {} as any;

const result = arr.lastIndexOf("abc");
});
8 changes: 8 additions & 0 deletions src/tests/filter-boolean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,11 @@ doNotExecute(() => {

type tests = [Expect<Equal<typeof result, never[]>>];
});

doNotExecute(() => {
const arr: string[] | number[] = {} as any;

const result = arr.filter((x) => typeof x === "string");

type tests = [Expect<Equal<typeof result, string[]>>];
});
Loading