Skip to content

Commit 08b9978

Browse files
committed
Add minimal lib.d.ts for array checking
1 parent 45d01b1 commit 08b9978

File tree

3 files changed

+101
-3
lines changed

3 files changed

+101
-3
lines changed
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
}

packages/core/test/snapshots/[email protected]

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,9 @@
467467
"/node_modules/typescript/lib/lib.d.ts",
468468
"/node_modules/available-regexp-flags/properties.d.ts"
469469
],
470-
"visibleProblems": []
470+
"visibleProblems": [
471+
0
472+
]
471473
},
472474
"bundler": {
473475
"name": "./properties",
@@ -886,5 +888,22 @@
886888
},
887889
"bundler": {}
888890
},
889-
"problems": []
891+
"problems": [
892+
{
893+
"kind": "NamedExports",
894+
"implementationFileName": "/node_modules/available-regexp-flags/properties.js",
895+
"typesFileName": "/node_modules/available-regexp-flags/properties.d.ts",
896+
"isMissingAllNamed": false,
897+
"missing": [
898+
"d",
899+
"g",
900+
"i",
901+
"m",
902+
"s",
903+
"u",
904+
"v",
905+
"y"
906+
]
907+
}
908+
]
890909
}

0 commit comments

Comments
 (0)