Skip to content

Commit 591cde8

Browse files
committed
removed BooleanConverter, using BooleanConstructor instead. Updated tests results for that.
1 parent d5e0701 commit 591cde8

33 files changed

+200
-98
lines changed

meldlocal.js

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/* eslint-disable @typescript-eslint/quotes */
2+
const cp = require("child_process");
3+
//const fs = require("fs/promises");
4+
const fs = require("fs");
5+
const path = require("path");
6+
const readlinem = require("readline");
7+
const dir = "tests/baselines/local/";
8+
9+
function escapeRegExp1(text) {
10+
return Array.from(text)
11+
.map(char => `\\u{${char.charCodeAt(0).toString(16)}}`)
12+
.join('');
13+
}
14+
function escapeRegExp2(text) {
15+
return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); // $& means the whole matched string
16+
}
17+
18+
19+
let idx = 2;
20+
let interactiveAccept = false;
21+
if (process.argv[idx]==="-i"){
22+
interactiveAccept = true;
23+
idx++;
24+
}
25+
26+
// eslint-disable-next-line prefer-const
27+
let basefilts = process.argv.slice(idx);
28+
//basefilts = basefilts.map(filt=>escapeRegExp2(filt));
29+
console.log(`basefilt: [${basefilts.length}] ${basefilts}`);
30+
basefilts.forEach((b,idx)=>{
31+
console.log(`baseline[${idx}]: ${b}, re.source: ${(new RegExp(b)).source}, re: ${new RegExp(b)}`);
32+
});
33+
34+
function askUser(question) {
35+
const readline = readlinem.createInterface({
36+
input: process.stdin,
37+
output: process.stdout
38+
});
39+
return new Promise(resolve => {
40+
readline.question(question, (ans) => {
41+
readline.close();
42+
resolve(ans);
43+
});
44+
});
45+
}
46+
47+
async function main(){
48+
const arrdirent = await fs.promises.readdir(dir,{ withFileTypes:true });
49+
arrdirent.forEach(de=>{
50+
if (de.isFile()){
51+
console.log(`de.name:${de.name}`);
52+
}
53+
else console.log(`de.name:${de.name} (dir)`);
54+
});
55+
arrdirent.reduce(async (promise,de)=>{
56+
await promise;
57+
if (de.isFile()){
58+
// if (!basefilts.every(filt=>de.name.includes(filt))) return;
59+
if (!basefilts.every(filt=>{
60+
const re = new RegExp(filt);
61+
const tmp = de.name+"";
62+
return tmp.match(re);
63+
})) return;
64+
if (de.name.endsWith(".symbols")) return;
65+
console.log(`de.name:${de.name}`);
66+
const right = dir+de.name;
67+
let left = right.replace("local","reference");
68+
if (left.endsWith("errors.txt.delete")){
69+
left = left.replace("errors.txt.delete","errors.txt");
70+
}
71+
const cmd = `meld ${left} ${right}`;
72+
console.log(cmd);
73+
cp.execSync(cmd);
74+
if (interactiveAccept && path.extname(de.name)===".types"){
75+
const accept = await askUser(`accept into baseline? Ny (${path.basename(de.name)})`);
76+
if (accept!=="y"){
77+
console.log(`not accepting ${de.name}`);
78+
}
79+
else {
80+
console.log(`accepting ${de.name}`);
81+
await fs.promises.copyFile(right,left);
82+
console.log(`copy ${right} -> ${left} success`);
83+
84+
const jsFile = right.replace(".types",".js");
85+
if (fs.existsSync(jsFile)){
86+
const jsFileLeft = left.replace(".types",".js");
87+
await fs.promises.copyFile(jsFile,jsFileLeft);
88+
console.log(`copy ${jsFile} -> ${jsFileLeft} success`);
89+
}
90+
91+
const symbolsFile = right.replace(".types",".symbols");
92+
if (fs.existsSync(symbolsFile)){
93+
const symbolsFileLeft = left.replace(".types",".symbols");
94+
await fs.promises.copyFile(symbolsFile,symbolsFileLeft);
95+
console.log(`copy ${symbolsFile} -> ${symbolsFileLeft} success`);
96+
}
97+
const errorsFile = right.replace(".types",".errors.txt");
98+
if (fs.existsSync(errorsFile)){
99+
const errorsFileLeft = left.replace(".types",".errors.txt");
100+
await fs.promises.copyFile(errorsFile,errorsFileLeft);
101+
console.log(`copy ${errorsFile} -> ${errorsFileLeft} success`);
102+
}
103+
}
104+
}
105+
}
106+
}, Promise.resolve());
107+
}
108+
109+
main()
110+
.then(()=>{ console.log("done");})
111+
.catch(err=>{ console.log(err); });
112+
113+
114+

src/harness/fourslashInterfaceImpl.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1123,7 +1123,6 @@ export namespace Completion {
11231123
interfaceEntry("StringConstructor"),
11241124
varEntry("Boolean"),
11251125
interfaceEntry("BooleanConstructor"),
1126-
interfaceEntry("BooleanConverter"),
11271126
varEntry("Number"),
11281127
interfaceEntry("NumberConstructor"),
11291128
interfaceEntry("TemplateStringsArray"),

src/lib/es5.d.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -536,11 +536,6 @@ interface BooleanConstructor {
536536
readonly prototype: Boolean;
537537
}
538538

539-
interface BooleanConverter {
540-
<T>(value?: T): boolean;
541-
readonly prototype: Boolean;
542-
}
543-
544539
declare var Boolean: BooleanConstructor;
545540

546541
interface Number {
@@ -1267,7 +1262,7 @@ interface ReadonlyArray<T> {
12671262
* @param predicate Must be exactly "Boolean"
12681263
* @param thisArg An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.
12691264
*/
1270-
filter(predicate: BooleanConverter, thisArg?: any): (T extends false | 0 | "" | null | undefined | 0n ? never : T)[];
1265+
filter(predicate: BooleanConstructor, thisArg?: any): (T extends false | 0 | "" | null | undefined | 0n ? never : T)[];
12711266
/**
12721267
* Returns the elements of an array that meet the condition specified in a callback function.
12731268
* @param predicate A function that accepts up to three arguments. The filter method calls the predicate function one time for each element in the array.
@@ -1464,7 +1459,7 @@ interface Array<T> {
14641459
* @param predicate Must be exactly "Boolean"
14651460
* @param thisArg An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.
14661461
*/
1467-
filter(predicate: BooleanConverter, thisArg?: any): (T extends false | 0 | "" | null | undefined | 0n ? never : T)[];
1462+
filter(predicate: BooleanConstructor, thisArg?: any): (T extends false | 0 | "" | null | undefined | 0n ? never : T)[];
14681463
/**
14691464
* Returns the elements of an array that meet the condition specified in a callback function.
14701465
* @param predicate A function that accepts up to three arguments. The filter method calls the predicate function one time for each element in the array.

tests/baselines/reference/arrayFilter.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ var foo = [
2323

2424
foo.filter(x => x.name); //should accepted all possible types not only boolean!
2525
>foo.filter(x => x.name) : { name: string; }[]
26-
>foo.filter : { <S extends { name: string; }>(predicate: (value: { name: string; }, index: number, array: { name: string; }[]) => value is S, thisArg?: any): S[]; (predicate: BooleanConverter, thisArg?: any): { name: string; }[]; (predicate: (value: { name: string; }, index: number, array: { name: string; }[]) => unknown, thisArg?: any): { name: string; }[]; }
26+
>foo.filter : { <S extends { name: string; }>(predicate: (value: { name: string; }, index: number, array: { name: string; }[]) => value is S, thisArg?: any): S[]; (predicate: BooleanConstructor, thisArg?: any): { name: string; }[]; (predicate: (value: { name: string; }, index: number, array: { name: string; }[]) => unknown, thisArg?: any): { name: string; }[]; }
2727
>foo : { name: string; }[]
28-
>filter : { <S extends { name: string; }>(predicate: (value: { name: string; }, index: number, array: { name: string; }[]) => value is S, thisArg?: any): S[]; (predicate: BooleanConverter, thisArg?: any): { name: string; }[]; (predicate: (value: { name: string; }, index: number, array: { name: string; }[]) => unknown, thisArg?: any): { name: string; }[]; }
28+
>filter : { <S extends { name: string; }>(predicate: (value: { name: string; }, index: number, array: { name: string; }[]) => value is S, thisArg?: any): S[]; (predicate: BooleanConstructor, thisArg?: any): { name: string; }[]; (predicate: (value: { name: string; }, index: number, array: { name: string; }[]) => unknown, thisArg?: any): { name: string; }[]; }
2929
>x => x.name : (x: { name: string; }) => string
3030
>x : { name: string; }
3131
>x.name : string

tests/baselines/reference/arrayFilterBooleanOverload.types

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@ const nullableValues = ['a', 'b', null]; // expect (string | null)[]
1010
const values1 = nullableValues.filter(Boolean); // expect string[]
1111
>values1 : string[]
1212
>nullableValues.filter(Boolean) : string[]
13-
>nullableValues.filter : { <S extends string | null>(predicate: (value: string | null, index: number, array: (string | null)[]) => value is S, thisArg?: any): S[]; (predicate: BooleanConverter, thisArg?: any): string[]; (predicate: (value: string | null, index: number, array: (string | null)[]) => unknown, thisArg?: any): (string | null)[]; }
13+
>nullableValues.filter : { <S extends string | null>(predicate: (value: string | null, index: number, array: (string | null)[]) => value is S, thisArg?: any): S[]; (predicate: BooleanConstructor, thisArg?: any): string[]; (predicate: (value: string | null, index: number, array: (string | null)[]) => unknown, thisArg?: any): (string | null)[]; }
1414
>nullableValues : (string | null)[]
15-
>filter : { <S extends string | null>(predicate: (value: string | null, index: number, array: (string | null)[]) => value is S, thisArg?: any): S[]; (predicate: BooleanConverter, thisArg?: any): string[]; (predicate: (value: string | null, index: number, array: (string | null)[]) => unknown, thisArg?: any): (string | null)[]; }
15+
>filter : { <S extends string | null>(predicate: (value: string | null, index: number, array: (string | null)[]) => value is S, thisArg?: any): S[]; (predicate: BooleanConstructor, thisArg?: any): string[]; (predicate: (value: string | null, index: number, array: (string | null)[]) => unknown, thisArg?: any): (string | null)[]; }
1616
>Boolean : BooleanConstructor
1717

1818
// @ts-expect-error
1919
const values2 = nullableValues.filter(new Boolean);
2020
>values2 : (string | null)[]
2121
>nullableValues.filter(new Boolean) : (string | null)[]
22-
>nullableValues.filter : { <S extends string | null>(predicate: (value: string | null, index: number, array: (string | null)[]) => value is S, thisArg?: any): S[]; (predicate: BooleanConverter, thisArg?: any): string[]; (predicate: (value: string | null, index: number, array: (string | null)[]) => unknown, thisArg?: any): (string | null)[]; }
22+
>nullableValues.filter : { <S extends string | null>(predicate: (value: string | null, index: number, array: (string | null)[]) => value is S, thisArg?: any): S[]; (predicate: BooleanConstructor, thisArg?: any): string[]; (predicate: (value: string | null, index: number, array: (string | null)[]) => unknown, thisArg?: any): (string | null)[]; }
2323
>nullableValues : (string | null)[]
24-
>filter : { <S extends string | null>(predicate: (value: string | null, index: number, array: (string | null)[]) => value is S, thisArg?: any): S[]; (predicate: BooleanConverter, thisArg?: any): string[]; (predicate: (value: string | null, index: number, array: (string | null)[]) => unknown, thisArg?: any): (string | null)[]; }
24+
>filter : { <S extends string | null>(predicate: (value: string | null, index: number, array: (string | null)[]) => value is S, thisArg?: any): S[]; (predicate: BooleanConstructor, thisArg?: any): string[]; (predicate: (value: string | null, index: number, array: (string | null)[]) => unknown, thisArg?: any): (string | null)[]; }
2525
>new Boolean : Boolean
2626
>Boolean : BooleanConstructor
2727

@@ -37,9 +37,9 @@ const arr = [0, 1, "", "foo", null] as const;
3737
const arr2 = arr.filter(Boolean); // expect ("foo" | 1)[]
3838
>arr2 : (1 | "foo")[]
3939
>arr.filter(Boolean) : (1 | "foo")[]
40-
>arr.filter : { <S extends "" | 0 | 1 | "foo" | null>(predicate: (value: "" | 0 | 1 | "foo" | null, index: number, array: readonly ("" | 0 | 1 | "foo" | null)[]) => value is S, thisArg?: any): S[]; (predicate: BooleanConverter, thisArg?: any): (1 | "foo")[]; (predicate: (value: "" | 0 | 1 | "foo" | null, index: number, array: readonly ("" | 0 | 1 | "foo" | null)[]) => unknown, thisArg?: any): ("" | 0 | 1 | "foo" | null)[]; }
40+
>arr.filter : { <S extends "" | 0 | 1 | "foo" | null>(predicate: (value: "" | 0 | 1 | "foo" | null, index: number, array: readonly ("" | 0 | 1 | "foo" | null)[]) => value is S, thisArg?: any): S[]; (predicate: BooleanConstructor, thisArg?: any): (1 | "foo")[]; (predicate: (value: "" | 0 | 1 | "foo" | null, index: number, array: readonly ("" | 0 | 1 | "foo" | null)[]) => unknown, thisArg?: any): ("" | 0 | 1 | "foo" | null)[]; }
4141
>arr : readonly [0, 1, "", "foo", null]
42-
>filter : { <S extends "" | 0 | 1 | "foo" | null>(predicate: (value: "" | 0 | 1 | "foo" | null, index: number, array: readonly ("" | 0 | 1 | "foo" | null)[]) => value is S, thisArg?: any): S[]; (predicate: BooleanConverter, thisArg?: any): (1 | "foo")[]; (predicate: (value: "" | 0 | 1 | "foo" | null, index: number, array: readonly ("" | 0 | 1 | "foo" | null)[]) => unknown, thisArg?: any): ("" | 0 | 1 | "foo" | null)[]; }
42+
>filter : { <S extends "" | 0 | 1 | "foo" | null>(predicate: (value: "" | 0 | 1 | "foo" | null, index: number, array: readonly ("" | 0 | 1 | "foo" | null)[]) => value is S, thisArg?: any): S[]; (predicate: BooleanConstructor, thisArg?: any): (1 | "foo")[]; (predicate: (value: "" | 0 | 1 | "foo" | null, index: number, array: readonly ("" | 0 | 1 | "foo" | null)[]) => unknown, thisArg?: any): ("" | 0 | 1 | "foo" | null)[]; }
4343
>Boolean : BooleanConstructor
4444

4545

tests/baselines/reference/booleanFilterAnyArray.types

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ var ys: any[];
4747
var ys = realanys.filter(Boolean)
4848
>ys : any[]
4949
>realanys.filter(Boolean) : any[]
50-
>realanys.filter : { <S extends any>(predicate: (value: any, index: number, array: any[]) => value is S, thisArg?: any): S[]; (predicate: BooleanConverter, thisArg?: any): any[]; (predicate: (value: any, index: number, array: any[]) => unknown, thisArg?: any): any[]; }
50+
>realanys.filter : { <S extends any>(predicate: (value: any, index: number, array: any[]) => value is S, thisArg?: any): S[]; (predicate: BooleanConstructor, thisArg?: any): any[]; (predicate: (value: any, index: number, array: any[]) => unknown, thisArg?: any): any[]; }
5151
>realanys : any[]
52-
>filter : { <S extends any>(predicate: (value: any, index: number, array: any[]) => value is S, thisArg?: any): S[]; (predicate: BooleanConverter, thisArg?: any): any[]; (predicate: (value: any, index: number, array: any[]) => unknown, thisArg?: any): any[]; }
52+
>filter : { <S extends any>(predicate: (value: any, index: number, array: any[]) => value is S, thisArg?: any): S[]; (predicate: BooleanConstructor, thisArg?: any): any[]; (predicate: (value: any, index: number, array: any[]) => unknown, thisArg?: any): any[]; }
5353
>Boolean : BooleanConstructor
5454

5555
var foo = [{ name: 'x' }]
@@ -66,9 +66,9 @@ var foor: Array<{name: string}>
6666
var foor = foo.filter(x => x.name)
6767
>foor : { name: string; }[]
6868
>foo.filter(x => x.name) : { name: string; }[]
69-
>foo.filter : { <S extends { name: string; }>(predicate: (value: { name: string; }, index: number, array: { name: string; }[]) => value is S, thisArg?: any): S[]; (predicate: BooleanConverter, thisArg?: any): { name: string; }[]; (predicate: (value: { name: string; }, index: number, array: { name: string; }[]) => unknown, thisArg?: any): { name: string; }[]; }
69+
>foo.filter : { <S extends { name: string; }>(predicate: (value: { name: string; }, index: number, array: { name: string; }[]) => value is S, thisArg?: any): S[]; (predicate: BooleanConstructor, thisArg?: any): { name: string; }[]; (predicate: (value: { name: string; }, index: number, array: { name: string; }[]) => unknown, thisArg?: any): { name: string; }[]; }
7070
>foo : { name: string; }[]
71-
>filter : { <S extends { name: string; }>(predicate: (value: { name: string; }, index: number, array: { name: string; }[]) => value is S, thisArg?: any): S[]; (predicate: BooleanConverter, thisArg?: any): { name: string; }[]; (predicate: (value: { name: string; }, index: number, array: { name: string; }[]) => unknown, thisArg?: any): { name: string; }[]; }
71+
>filter : { <S extends { name: string; }>(predicate: (value: { name: string; }, index: number, array: { name: string; }[]) => value is S, thisArg?: any): S[]; (predicate: BooleanConstructor, thisArg?: any): { name: string; }[]; (predicate: (value: { name: string; }, index: number, array: { name: string; }[]) => unknown, thisArg?: any): { name: string; }[]; }
7272
>x => x.name : (x: { name: string; }) => string
7373
>x : { name: string; }
7474
>x.name : string
@@ -81,12 +81,12 @@ var foos: Array<boolean>
8181
var foos = [true, true, false, null].filter((thing): thing is boolean => thing !== null)
8282
>foos : boolean[]
8383
>[true, true, false, null].filter((thing): thing is boolean => thing !== null) : boolean[]
84-
>[true, true, false, null].filter : { <S extends boolean>(predicate: (value: boolean, index: number, array: boolean[]) => value is S, thisArg?: any): S[]; (predicate: BooleanConverter, thisArg?: any): true[]; (predicate: (value: boolean, index: number, array: boolean[]) => unknown, thisArg?: any): boolean[]; }
84+
>[true, true, false, null].filter : { <S extends boolean>(predicate: (value: boolean, index: number, array: boolean[]) => value is S, thisArg?: any): S[]; (predicate: BooleanConstructor, thisArg?: any): true[]; (predicate: (value: boolean, index: number, array: boolean[]) => unknown, thisArg?: any): boolean[]; }
8585
>[true, true, false, null] : boolean[]
8686
>true : true
8787
>true : true
8888
>false : false
89-
>filter : { <S extends boolean>(predicate: (value: boolean, index: number, array: boolean[]) => value is S, thisArg?: any): S[]; (predicate: BooleanConverter, thisArg?: any): true[]; (predicate: (value: boolean, index: number, array: boolean[]) => unknown, thisArg?: any): boolean[]; }
89+
>filter : { <S extends boolean>(predicate: (value: boolean, index: number, array: boolean[]) => value is S, thisArg?: any): S[]; (predicate: BooleanConstructor, thisArg?: any): true[]; (predicate: (value: boolean, index: number, array: boolean[]) => unknown, thisArg?: any): boolean[]; }
9090
>(thing): thing is boolean => thing !== null : (thing: boolean) => thing is boolean
9191
>thing : boolean
9292
>thing !== null : boolean

tests/baselines/reference/contextuallyTypeAsyncFunctionReturnType.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,11 @@ async function copyExtensions(
211211
>fromExtensions .filter((e) => !e.isApplicationScoped) .map(async (e) => [e, await scanMetadata(e)]) : Promise<[ILocalExtension, Metadata]>[]
212212
>fromExtensions .filter((e) => !e.isApplicationScoped) .map : <U>(callbackfn: (value: ILocalExtension, index: number, array: ILocalExtension[]) => U, thisArg?: any) => U[]
213213
>fromExtensions .filter((e) => !e.isApplicationScoped) : ILocalExtension[]
214-
>fromExtensions .filter : { <S extends ILocalExtension>(predicate: (value: ILocalExtension, index: number, array: ILocalExtension[]) => value is S, thisArg?: any): S[]; (predicate: BooleanConverter, thisArg?: any): ILocalExtension[]; (predicate: (value: ILocalExtension, index: number, array: ILocalExtension[]) => unknown, thisArg?: any): ILocalExtension[]; }
214+
>fromExtensions .filter : { <S extends ILocalExtension>(predicate: (value: ILocalExtension, index: number, array: ILocalExtension[]) => value is S, thisArg?: any): S[]; (predicate: BooleanConstructor, thisArg?: any): ILocalExtension[]; (predicate: (value: ILocalExtension, index: number, array: ILocalExtension[]) => unknown, thisArg?: any): ILocalExtension[]; }
215215
>fromExtensions : ILocalExtension[]
216216

217217
.filter((e) => !e.isApplicationScoped)
218-
>filter : { <S extends ILocalExtension>(predicate: (value: ILocalExtension, index: number, array: ILocalExtension[]) => value is S, thisArg?: any): S[]; (predicate: BooleanConverter, thisArg?: any): ILocalExtension[]; (predicate: (value: ILocalExtension, index: number, array: ILocalExtension[]) => unknown, thisArg?: any): ILocalExtension[]; }
218+
>filter : { <S extends ILocalExtension>(predicate: (value: ILocalExtension, index: number, array: ILocalExtension[]) => value is S, thisArg?: any): S[]; (predicate: BooleanConstructor, thisArg?: any): ILocalExtension[]; (predicate: (value: ILocalExtension, index: number, array: ILocalExtension[]) => unknown, thisArg?: any): ILocalExtension[]; }
219219
>(e) => !e.isApplicationScoped : (e: ILocalExtension) => boolean
220220
>e : ILocalExtension
221221
>!e.isApplicationScoped : boolean

0 commit comments

Comments
 (0)