Skip to content

Commit 116dc05

Browse files
authored
Merge pull request #233 from arethetypeswrong/bug/named-exports-array
Exclude array/tuple properties from expected named exports
2 parents f4729b8 + 59940cd commit 116dc05

File tree

6 files changed

+998
-1
lines changed

6 files changed

+998
-1
lines changed

.changeset/clever-ghosts-begin.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@arethetypeswrong/core": patch
3+
---
4+
5+
Exclude array/tuple properties from expected named exports

packages/core/src/internal/checks/namedExports.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ export default defineCheck({
3838
}
3939

4040
const typeChecker = host.createAuxiliaryProgram([typesFileName]).getTypeChecker();
41+
const moduleType = typeChecker.getTypeOfSymbol(typeChecker.resolveExternalModuleSymbol(typesSourceFile.symbol));
42+
if (typeChecker.isArrayLikeType(moduleType) || typeChecker.getPropertyOfType(moduleType, "0")) {
43+
return;
44+
}
4145
const expectedNames = Array.from(
4246
new Set(
4347
typeChecker
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// The contents of this string are derived from typescript/lib/lib.es5.d.ts.
2+
// These types are all that are needed for the NamedExports check to work.
3+
4+
/*! *****************************************************************************
5+
Copyright (c) Microsoft Corporation. All rights reserved.
6+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
7+
this file except in compliance with the License. You may obtain a copy of the
8+
License at http://www.apache.org/licenses/LICENSE-2.0
9+
10+
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
11+
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
12+
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
13+
MERCHANTABLITY OR NON-INFRINGEMENT.
14+
15+
See the Apache Version 2.0 License for specific language governing permissions
16+
and limitations under the License.
17+
***************************************************************************** */
18+
export default `
19+
interface ReadonlyArray<T> {
20+
readonly length: number;
21+
toString(): string;
22+
toLocaleString(): string;
23+
concat(...items: ConcatArray<T>[]): T[];
24+
concat(...items: (T | ConcatArray<T>)[]): T[];
25+
join(separator?: string): string;
26+
slice(start?: number, end?: number): T[];
27+
indexOf(searchElement: T, fromIndex?: number): number;
28+
lastIndexOf(searchElement: T, fromIndex?: number): number;
29+
every<S extends T>(predicate: (value: T, index: number, array: readonly T[]) => value is S, thisArg?: any): this is readonly S[];
30+
every(predicate: (value: T, index: number, array: readonly T[]) => unknown, thisArg?: any): boolean;
31+
some(predicate: (value: T, index: number, array: readonly T[]) => unknown, thisArg?: any): boolean;
32+
forEach(callbackfn: (value: T, index: number, array: readonly T[]) => void, thisArg?: any): void;
33+
map<U>(callbackfn: (value: T, index: number, array: readonly T[]) => U, thisArg?: any): U[];
34+
filter<S extends T>(predicate: (value: T, index: number, array: readonly T[]) => value is S, thisArg?: any): S[];
35+
filter(predicate: (value: T, index: number, array: readonly T[]) => unknown, thisArg?: any): T[];
36+
reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: readonly T[]) => T): T;
37+
reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: readonly T[]) => T, initialValue: T): T;
38+
reduce<U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: readonly T[]) => U, initialValue: U): U;
39+
reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: readonly T[]) => T): T;
40+
reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: readonly T[]) => T, initialValue: T): T;
41+
reduceRight<U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: readonly T[]) => U, initialValue: U): U;
42+
readonly [n: number]: T;
43+
}
44+
45+
interface Array<T> {
46+
length: number;
47+
toString(): string;
48+
toLocaleString(): string;
49+
pop(): T | undefined;
50+
push(...items: T[]): number;
51+
concat(...items: ConcatArray<T>[]): T[];
52+
concat(...items: (T | ConcatArray<T>)[]): T[];
53+
join(separator?: string): string;
54+
reverse(): T[];
55+
shift(): T | undefined;
56+
slice(start?: number, end?: number): T[];
57+
sort(compareFn?: (a: T, b: T) => number): this;
58+
splice(start: number, deleteCount?: number): T[];
59+
splice(start: number, deleteCount: number, ...items: T[]): T[];
60+
unshift(...items: T[]): number;
61+
indexOf(searchElement: T, fromIndex?: number): number;
62+
lastIndexOf(searchElement: T, fromIndex?: number): number;
63+
every<S extends T>(predicate: (value: T, index: number, array: T[]) => value is S, thisArg?: any): this is S[];
64+
every(predicate: (value: T, index: number, array: T[]) => unknown, thisArg?: any): boolean;
65+
some(predicate: (value: T, index: number, array: T[]) => unknown, thisArg?: any): boolean;
66+
forEach(callbackfn: (value: T, index: number, array: T[]) => void, thisArg?: any): void;
67+
map<U>(callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: any): U[];
68+
filter<S extends T>(predicate: (value: T, index: number, array: T[]) => value is S, thisArg?: any): S[];
69+
filter(predicate: (value: T, index: number, array: T[]) => unknown, thisArg?: any): T[];
70+
reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T): T;
71+
reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue: T): T;
72+
reduce<U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): U;
73+
reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T): T;
74+
reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue: T): T;
75+
reduceRight<U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): U;
76+
[n: number]: T;
77+
}
78+
`;

packages/core/src/internal/multiCompilerHost.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import ts from "typescript";
22
import { LRUCache } from "lru-cache";
3+
import minimalLibDts from "./minimalLibDts.js";
34
import type { ModuleKind } from "../types.js";
45
import type { Package } from "../createPackage.js";
56

@@ -225,7 +226,7 @@ export class CompilerHostWrapper {
225226
if (cached) {
226227
return cached;
227228
}
228-
const content = fileName.startsWith("/node_modules/typescript/lib") ? "" : fs.tryReadFile(fileName);
229+
const content = fileName === "/node_modules/typescript/lib/lib.d.ts" ? minimalLibDts : fs.tryReadFile(fileName);
229230
if (content === undefined) {
230231
return undefined;
231232
}
6.65 KB
Binary file not shown.

0 commit comments

Comments
 (0)