Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d856f09

Browse files
authoredMar 16, 2025··
refactor: refactor aliasing system (#68)
* refactor: renew aliasing logic * chore: revert docs diff change
1 parent 1d4bc98 commit d856f09

File tree

8 files changed

+698
-573
lines changed

8 files changed

+698
-573
lines changed
 

‎build/logic/ReplacementMap.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import type ts from "typescript";
2+
3+
export type ReplacementTarget = (
4+
| {
5+
type: "interface";
6+
originalStatement: ts.InterfaceDeclaration;
7+
members: Map<
8+
string,
9+
{
10+
member: ts.TypeElement;
11+
text: string;
12+
}[]
13+
>;
14+
}
15+
| {
16+
type: "declare-global";
17+
originalStatement: ts.ModuleDeclaration;
18+
statements: ReplacementMap;
19+
}
20+
| {
21+
type: "non-interface";
22+
statement: ts.Statement;
23+
}
24+
) & {
25+
optional: boolean;
26+
sourceFile: ts.SourceFile;
27+
};
28+
29+
export type ReplacementMap = Map<ReplacementName, ReplacementTarget[]>;
30+
31+
export const declareGlobalSymbol = Symbol("declare global");
32+
export type ReplacementName = string | typeof declareGlobalSymbol;
33+
34+
export function mergeReplacementMapInto(
35+
target: ReplacementMap,
36+
source: ReplacementMap,
37+
): void {
38+
for (const [key, value] of source) {
39+
target.set(key, [...(target.get(key) ?? []), ...value]);
40+
}
41+
}

‎build/logic/generate.ts

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ import { upsert } from "../util/upsert";
55
import { getStatementDeclName } from "./ast/getStatementDeclName";
66
import {
77
declareGlobalSymbol,
8-
ReplacementMap,
9-
ReplacementName,
10-
ReplacementTarget,
11-
scanBetterFile,
12-
} from "./scanBetterFile";
8+
mergeReplacementMapInto,
9+
type ReplacementMap,
10+
type ReplacementName,
11+
type ReplacementTarget,
12+
} from "./ReplacementMap";
13+
import { loadAliasFile, scanBetterFile } from "./scanBetterFile";
1314

1415
type GenerateOptions = {
1516
emitOriginalAsComment?: boolean;
@@ -41,6 +42,11 @@ export function generate(
4142
: "";
4243

4344
const replacementTargets = scanBetterFile(printer, targetFile);
45+
const { replacementMap: aliasReplacementMap } = loadAliasFile(
46+
printer,
47+
targetFile,
48+
);
49+
mergeReplacementMapInto(replacementTargets, aliasReplacementMap);
4450

4551
if (replacementTargets.size === 0) {
4652
return result + originalFile.text;
@@ -130,11 +136,21 @@ function generateStatements(
130136
for (const name of consumedReplacements) {
131137
replacementTargets.delete(name);
132138
}
133-
if (replacementTargets.size > 0) {
134-
result += "// --------------------\n";
135-
}
139+
140+
let lineInserted = false;
136141
for (const target of replacementTargets.values()) {
137142
for (const statement of target) {
143+
if (statement.optional) {
144+
// Since target from aliases may not be present in the original file,
145+
// aliases that have not been consumed are skipped.
146+
continue;
147+
}
148+
149+
if (!lineInserted) {
150+
result += "// --------------------\n";
151+
lineInserted = true;
152+
}
153+
138154
if (statement.type === "non-interface") {
139155
result += statement.statement.getFullText(statement.sourceFile);
140156
} else {

‎build/logic/scanBetterFile.ts

Lines changed: 140 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,67 @@ import { alias } from "../util/alias";
44
import { upsert } from "../util/upsert";
55
import { getStatementDeclName } from "./ast/getStatementDeclName";
66
import { projectDir } from "./projectDir";
7+
import {
8+
declareGlobalSymbol,
9+
type ReplacementMap,
10+
type ReplacementName,
11+
type ReplacementTarget,
12+
} from "./ReplacementMap";
713

814
const betterLibDir = path.join(projectDir, "lib");
15+
const aliasFilePath = path.join(betterLibDir, "alias.d.ts");
916

10-
export type ReplacementTarget = (
11-
| {
12-
type: "interface";
13-
originalStatement: ts.InterfaceDeclaration;
14-
members: Map<
15-
string,
16-
{
17-
member: ts.TypeElement;
18-
text: string;
19-
}[]
20-
>;
21-
}
22-
| {
23-
type: "declare-global";
24-
originalStatement: ts.ModuleDeclaration;
25-
statements: ReplacementMap;
17+
type AliasFile = {
18+
replacementMap: ReplacementMap;
19+
};
20+
21+
// Cache for alias file statements
22+
let aliasFileCache: ts.SourceFile | undefined;
23+
24+
/**
25+
* Load the alias file applied to the target file.
26+
*/
27+
export function loadAliasFile(
28+
printer: ts.Printer,
29+
targetFileName: string,
30+
): AliasFile {
31+
if (!aliasFileCache) {
32+
const aliasProgram = ts.createProgram([aliasFilePath], {});
33+
const aliasFile = aliasProgram.getSourceFile(aliasFilePath);
34+
35+
if (!aliasFile) {
36+
throw new Error("Alias file not found in the program");
2637
}
27-
| {
28-
type: "non-interface";
29-
statement: ts.Statement;
38+
aliasFileCache = aliasFile;
39+
}
40+
const aliasFile = aliasFileCache;
41+
const statements = aliasFile.statements.flatMap((statement) => {
42+
const name = getStatementDeclName(statement) ?? "";
43+
const aliases = alias.get(name);
44+
if (!aliases) {
45+
return [statement];
3046
}
31-
) & {
32-
sourceFile: ts.SourceFile;
33-
};
47+
return aliases.map((aliasDetails) => {
48+
if (aliasDetails.file !== targetFileName) {
49+
return statement;
50+
}
51+
return replaceAliases(statement, aliasDetails.replacement);
52+
});
53+
});
3454

35-
export type ReplacementMap = Map<ReplacementName, ReplacementTarget[]>;
55+
// Scan the target file
56+
const replacementMap = scanStatements(printer, statements, aliasFile);
57+
// mark everything as optional
58+
for (const targets of replacementMap.values()) {
59+
for (const target of targets) {
60+
target.optional = true;
61+
}
62+
}
3663

37-
export const declareGlobalSymbol = Symbol("declare global");
38-
export type ReplacementName = string | typeof declareGlobalSymbol;
64+
return {
65+
replacementMap,
66+
};
67+
}
3968

4069
/**
4170
* Scan better lib file to determine which statements need to be replaced.
@@ -56,104 +85,117 @@ export function scanBetterFile(
5685

5786
function scanStatements(
5887
printer: ts.Printer,
59-
statements: ts.NodeArray<ts.Statement>,
88+
statements: readonly ts.Statement[],
6089
sourceFile: ts.SourceFile,
6190
): ReplacementMap {
6291
const replacementTargets = new Map<ReplacementName, ReplacementTarget[]>();
6392
for (const statement of statements) {
6493
const name = getStatementDeclName(statement) ?? "";
65-
const aliasesMap =
66-
alias.get(name) ?? new Map([[name, new Map<string, string>()]]);
67-
for (const [targetName, typeMap] of aliasesMap) {
68-
const transformedStatement = replaceAliases(statement, typeMap);
69-
if (ts.isInterfaceDeclaration(transformedStatement)) {
70-
const members = new Map<
71-
string,
72-
{
73-
member: ts.TypeElement;
74-
text: string;
75-
}[]
76-
>();
77-
for (const member of transformedStatement.members) {
78-
const memberName = member.name?.getText(sourceFile) ?? "";
79-
upsert(members, memberName, (members = []) => {
80-
const leadingSpacesMatch = /^\s*/.exec(
81-
member.getFullText(sourceFile),
82-
);
83-
const leadingSpaces =
84-
leadingSpacesMatch !== null ? leadingSpacesMatch[0] : "";
85-
members.push({
86-
member,
87-
text:
88-
leadingSpaces +
89-
printer.printNode(ts.EmitHint.Unspecified, member, sourceFile),
90-
});
91-
return members;
92-
});
93-
}
94-
upsert(replacementTargets, targetName, (targets = []) => {
95-
targets.push({
96-
type: "interface",
97-
members,
98-
originalStatement: transformedStatement,
99-
sourceFile: sourceFile,
94+
const transformedStatement = statement;
95+
if (ts.isInterfaceDeclaration(transformedStatement)) {
96+
const members = new Map<
97+
string,
98+
{
99+
member: ts.TypeElement;
100+
text: string;
101+
}[]
102+
>();
103+
for (const member of transformedStatement.members) {
104+
const memberName = member.name?.getText(sourceFile) ?? "";
105+
upsert(members, memberName, (members = []) => {
106+
const leadingSpacesMatch = /^\s*/.exec(
107+
member.getFullText(sourceFile),
108+
);
109+
const leadingSpaces =
110+
leadingSpacesMatch !== null ? leadingSpacesMatch[0] : "";
111+
members.push({
112+
member,
113+
text:
114+
leadingSpaces +
115+
printer.printNode(ts.EmitHint.Unspecified, member, sourceFile),
100116
});
101-
return targets;
117+
return members;
102118
});
103-
} else if (
104-
ts.isModuleDeclaration(transformedStatement) &&
105-
ts.isIdentifier(transformedStatement.name) &&
106-
transformedStatement.name.text === "global"
107-
) {
108-
// declare global
109-
upsert(replacementTargets, declareGlobalSymbol, (targets = []) => {
110-
targets.push({
111-
type: "declare-global",
112-
originalStatement: transformedStatement,
113-
statements:
114-
transformedStatement.body &&
115-
ts.isModuleBlock(transformedStatement.body)
116-
? scanStatements(
117-
printer,
118-
transformedStatement.body.statements,
119-
sourceFile,
120-
)
121-
: new Map(),
122-
sourceFile: sourceFile,
123-
});
124-
return targets;
119+
}
120+
upsert(replacementTargets, name, (targets = []) => {
121+
targets.push({
122+
type: "interface",
123+
members,
124+
originalStatement: transformedStatement,
125+
optional: false,
126+
sourceFile: sourceFile,
125127
});
126-
} else {
127-
upsert(replacementTargets, targetName, (statements = []) => {
128-
statements.push({
129-
type: "non-interface",
130-
statement: transformedStatement,
131-
sourceFile: sourceFile,
132-
});
133-
return statements;
128+
return targets;
129+
});
130+
} else if (
131+
ts.isModuleDeclaration(transformedStatement) &&
132+
ts.isIdentifier(transformedStatement.name) &&
133+
transformedStatement.name.text === "global"
134+
) {
135+
// declare global
136+
upsert(replacementTargets, declareGlobalSymbol, (targets = []) => {
137+
targets.push({
138+
type: "declare-global",
139+
originalStatement: transformedStatement,
140+
statements:
141+
transformedStatement.body &&
142+
ts.isModuleBlock(transformedStatement.body)
143+
? scanStatements(
144+
printer,
145+
transformedStatement.body.statements,
146+
sourceFile,
147+
)
148+
: new Map(),
149+
optional: false,
150+
sourceFile: sourceFile,
134151
});
135-
}
152+
return targets;
153+
});
154+
} else {
155+
upsert(replacementTargets, name, (statements = []) => {
156+
statements.push({
157+
type: "non-interface",
158+
statement: transformedStatement,
159+
optional: false,
160+
sourceFile: sourceFile,
161+
});
162+
return statements;
163+
});
136164
}
137165
}
138166
return replacementTargets;
139167
}
140168

141169
function replaceAliases(
142170
statement: ts.Statement,
143-
typeMap: Map<string, string>,
171+
replacement: Map<string, string>,
144172
): ts.Statement {
145-
if (typeMap.size === 0) return statement;
146173
return ts.transform(statement, [
147174
(context) => (sourceStatement) => {
148175
const visitor = (node: ts.Node): ts.Node => {
176+
if (ts.isInterfaceDeclaration(node)) {
177+
const toName = replacement.get(node.name.text);
178+
if (toName === undefined) {
179+
return node;
180+
}
181+
const visited = ts.visitEachChild(node, visitor, context);
182+
return ts.factory.updateInterfaceDeclaration(
183+
visited,
184+
visited.modifiers,
185+
ts.factory.createIdentifier(toName),
186+
visited.typeParameters,
187+
visited.heritageClauses,
188+
visited.members,
189+
);
190+
}
149191
if (ts.isTypeReferenceNode(node) && ts.isIdentifier(node.typeName)) {
150-
const replacementType = typeMap.get(node.typeName.text);
151-
if (replacementType === undefined) {
192+
const toName = replacement.get(node.typeName.text);
193+
if (toName === undefined) {
152194
return node;
153195
}
154196
return ts.factory.updateTypeReferenceNode(
155197
node,
156-
ts.factory.createIdentifier(replacementType),
198+
ts.factory.createIdentifier(toName),
157199
node.typeArguments,
158200
);
159201
}

‎build/util/alias.ts

Lines changed: 69 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,72 @@
1-
const aliasArray: [string, string[]][] = [
1+
export type AliasDetails = {
2+
/**
3+
* File to which this alias applies.
4+
*/
5+
file: string;
6+
/**
7+
* Needed replacement.
8+
*/
9+
replacement: Map<string, string>;
10+
};
11+
12+
const es5TypedArrays = [
13+
"Int8Array",
14+
"Uint8Array",
15+
"Uint8ClampedArray",
16+
"Int16Array",
17+
"Uint16Array",
18+
"Int32Array",
19+
"Uint32Array",
20+
"Float32Array",
21+
"Float64Array",
22+
"Float16Array",
23+
];
24+
25+
const es2020TypedBigIntArrays = ["BigInt64Array", "BigUint64Array"];
26+
27+
export const alias = new Map([
228
[
329
"TypedNumberArray",
4-
[
5-
"Int8Array",
6-
"Uint8Array",
7-
"Uint8ClampedArray",
8-
"Int16Array",
9-
"Uint16Array",
10-
"Int32Array",
11-
"Uint32Array",
12-
"Float32Array",
13-
"Float64Array",
14-
],
30+
es5TypedArrays.map((name) => ({
31+
file: "lib.es5.d.ts",
32+
replacement: new Map([["TypedNumberArray", name]]),
33+
})),
1534
],
16-
["TypedBigIntArray", ["BigInt64Array", "BigUint64Array"]],
17-
];
18-
19-
export const alias = new Map(
20-
aliasArray.flatMap(([originalType, replacementTypes]) => [
21-
[
22-
originalType,
23-
new Map(
24-
replacementTypes.map((replacement) => [
25-
replacement,
26-
new Map([
27-
[originalType, replacement],
28-
[`${originalType}Constructor`, `${replacement}Constructor`],
29-
]),
30-
]),
31-
),
32-
],
33-
[
34-
`${originalType}Constructor`,
35-
new Map(
36-
replacementTypes.map((replacement) => [
37-
`${replacement}Constructor`,
38-
new Map([
39-
[originalType, replacement],
40-
[`${originalType}Constructor`, `${replacement}Constructor`],
41-
]),
42-
]),
43-
),
44-
],
45-
]),
46-
);
35+
[
36+
"TypedNumberArrayConstructor",
37+
es5TypedArrays.map((name) => ({
38+
file: "lib.es5.d.ts",
39+
replacement: new Map([
40+
["TypedNumberArray", name],
41+
["TypedNumberArrayConstructor", `${name}Constructor`],
42+
]),
43+
})),
44+
],
45+
[
46+
"TypedNumberArrayConstructorIter",
47+
es5TypedArrays.map((name) => ({
48+
file: "lib.es2015.iterable.d.ts",
49+
replacement: new Map([
50+
["TypedNumberArray", name],
51+
["TypedNumberArrayConstructorIter", `${name}Constructor`],
52+
]),
53+
})),
54+
],
55+
[
56+
"TypedBigIntArray",
57+
es2020TypedBigIntArrays.map((name) => ({
58+
file: "lib.es2020.bigint.d.ts",
59+
replacement: new Map([["TypedBigIntArray", name]]),
60+
})),
61+
],
62+
[
63+
"TypedBigIntArrayConstructor",
64+
es2020TypedBigIntArrays.map((name) => ({
65+
file: "lib.es2020.bigint.d.ts",
66+
replacement: new Map([
67+
["TypedBigIntArray", name],
68+
["TypedBigIntArrayConstructor", `${name}Constructor`],
69+
]),
70+
})),
71+
],
72+
]);

‎lib/alias.d.ts

Lines changed: 424 additions & 0 deletions
Large diffs are not rendered by default.

‎lib/lib.es2015.iterable.d.ts

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -63,24 +63,3 @@ interface PromiseConstructor {
6363
interface MapConstructor {
6464
new <K, V>(iterable?: Iterable<readonly [K, V]> | null): Map<K, V>;
6565
}
66-
67-
interface TypedNumberArrayConstructor {
68-
/**
69-
* Creates an array from an iterable object.
70-
* @param iterable An iterable object to convert to an array.
71-
*/
72-
from(
73-
iterable: Iterable<number> | ArrayLike<number>,
74-
): TypedNumberArray<ArrayBuffer>;
75-
/**
76-
* Creates an array from an iterable object.
77-
* @param iterable An iterable object to convert to an array.
78-
* @param mapfn A mapping function to call on every element of the array.
79-
* @param thisArg Value of 'this' used to invoke the mapfn.
80-
*/
81-
from<T, This = undefined>(
82-
iterable: Iterable<T> | ArrayLike<T>,
83-
mapfn: (this: This, v: T, k: number) => number,
84-
thisArg?: This,
85-
): TypedNumberArray<ArrayBuffer>;
86-
}

‎lib/lib.es2020.bigint.d.ts

Lines changed: 0 additions & 207 deletions
This file was deleted.

‎lib/lib.es5.d.ts

Lines changed: 0 additions & 196 deletions
Original file line numberDiff line numberDiff line change
@@ -643,202 +643,6 @@ interface Promise<T> extends PromiseLike<T> {
643643
): Promise<T | U>;
644644
}
645645

646-
interface TypedNumberArray<
647-
TArrayBuffer extends ArrayBufferLike = ArrayBufferLike,
648-
> {
649-
/**
650-
* Determines whether all the members of an array satisfy the specified test.
651-
* @param predicate A function that accepts up to three arguments. The every method calls
652-
* the predicate function for each element in the array until the predicate returns a value
653-
* which is coercible to the Boolean value false, or until the end of the array.
654-
* @param thisArg An object to which the this keyword can refer in the predicate function.
655-
* If thisArg is omitted, undefined is used as the this value.
656-
*/
657-
every<This = undefined>(
658-
predicate: (
659-
this: This,
660-
value: number,
661-
index: number,
662-
array: this,
663-
) => boolean,
664-
thisArg?: This,
665-
): boolean;
666-
/**
667-
* Returns the elements of an array that meet the condition specified in a callback function.
668-
* @param predicate A function that accepts up to three arguments. The filter method calls
669-
* the predicate function one time for each element in the array.
670-
* @param thisArg An object to which the this keyword can refer in the predicate function.
671-
* If thisArg is omitted, undefined is used as the this value.
672-
*/
673-
filter<This = undefined>(
674-
predicate: (
675-
this: This,
676-
value: number,
677-
index: number,
678-
array: this,
679-
) => boolean,
680-
thisArg?: This,
681-
): TypedNumberArray;
682-
/**
683-
* Returns the value of the first element in the array where predicate is true, and undefined
684-
* otherwise.
685-
* @param predicate find calls predicate once for each element of the array, in ascending
686-
* order, until it finds one where predicate returns true. If such an element is found, find
687-
* immediately returns that element value. Otherwise, find returns undefined.
688-
* @param thisArg If provided, it will be used as the this value for each invocation of
689-
* predicate. If it is not provided, undefined is used instead.
690-
*/
691-
find<This = undefined>(
692-
predicate: (this: This, value: number, index: number, obj: this) => boolean,
693-
thisArg?: This,
694-
): number | undefined;
695-
/**
696-
* Returns the index of the first element in the array where predicate is true, and -1
697-
* otherwise.
698-
* @param predicate find calls predicate once for each element of the array, in ascending
699-
* order, until it finds one where predicate returns true. If such an element is found,
700-
* findIndex immediately returns that element index. Otherwise, findIndex returns -1.
701-
* @param thisArg If provided, it will be used as the this value for each invocation of
702-
* predicate. If it is not provided, undefined is used instead.
703-
*/
704-
findIndex<This = undefined>(
705-
predicate: (this: This, value: number, index: number, obj: this) => boolean,
706-
thisArg?: This,
707-
): number;
708-
/**
709-
* Performs the specified action for each element in an array.
710-
* @param callbackfn A function that accepts up to three arguments. forEach calls the
711-
* callbackfn function one time for each element in the array.
712-
* @param thisArg An object to which the this keyword can refer in the callbackfn function.
713-
* If thisArg is omitted, undefined is used as the this value.
714-
*/
715-
forEach<This = undefined>(
716-
callbackfn: (this: This, value: number, index: number, array: this) => void,
717-
thisArg?: This,
718-
): void;
719-
/**
720-
* Calls a defined callback function on each element of an array, and returns an array that
721-
* contains the results.
722-
* @param callbackfn A function that accepts up to three arguments. The map method calls the
723-
* callbackfn function one time for each element in the array.
724-
* @param thisArg An object to which the this keyword can refer in the callbackfn function.
725-
* If thisArg is omitted, undefined is used as the this value.
726-
*/
727-
map<This = undefined>(
728-
callbackfn: (
729-
this: This,
730-
value: number,
731-
index: number,
732-
array: this,
733-
) => number,
734-
thisArg?: This,
735-
): TypedNumberArray;
736-
/**
737-
* Calls the specified callback function for all the elements in an array. The return value of
738-
* the callback function is the accumulated result, and is provided as an argument in the next
739-
* call to the callback function.
740-
* @param callbackfn A function that accepts up to four arguments. The reduce method calls the
741-
* callbackfn function one time for each element in the array.
742-
*/
743-
reduce<U = number>(
744-
callbackfn: (
745-
previousValue: number | U,
746-
currentValue: number,
747-
currentIndex: number,
748-
array: this,
749-
) => U,
750-
): number | U;
751-
/**
752-
* Calls the specified callback function for all the elements in an array. The return value of
753-
* the callback function is the accumulated result, and is provided as an argument in the next
754-
* call to the callback function.
755-
* @param callbackfn A function that accepts up to four arguments. The reduce method calls the
756-
* callbackfn function one time for each element in the array.
757-
* @param initialValue If initialValue is specified, it is used as the initial value to start
758-
* the accumulation. The first call to the callbackfn function provides this value as an argument
759-
* instead of an array value.
760-
*/
761-
reduce<U = number>(
762-
callbackfn: (
763-
previousValue: U,
764-
currentValue: number,
765-
currentIndex: number,
766-
array: this,
767-
) => U,
768-
initialValue: U,
769-
): U;
770-
/**
771-
* Calls the specified callback function for all the elements in an array, in descending order.
772-
* The return value of the callback function is the accumulated result, and is provided as an
773-
* argument in the next call to the callback function.
774-
* @param callbackfn A function that accepts up to four arguments. The reduceRight method calls
775-
* the callbackfn function one time for each element in the array.
776-
*/
777-
reduceRight<U = number>(
778-
callbackfn: (
779-
previousValue: number | U,
780-
currentValue: number,
781-
currentIndex: number,
782-
array: this,
783-
) => U,
784-
): number | U;
785-
/**
786-
* Calls the specified callback function for all the elements in an array, in descending order.
787-
* The return value of the callback function is the accumulated result, and is provided as an
788-
* argument in the next call to the callback function.
789-
* @param callbackfn A function that accepts up to four arguments. The reduceRight method calls
790-
* the callbackfn function one time for each element in the array.
791-
* @param initialValue If initialValue is specified, it is used as the initial value to start
792-
* the accumulation. The first call to the callbackfn function provides this value as an argument
793-
* instead of an array value.
794-
*/
795-
reduceRight<U = number>(
796-
callbackfn: (
797-
previousValue: U,
798-
currentValue: number,
799-
currentIndex: number,
800-
array: this,
801-
) => U,
802-
initialValue: U,
803-
): U;
804-
/**
805-
* Determines whether the specified callback function returns true for any element of an array.
806-
* @param predicate A function that accepts up to three arguments. The some method calls
807-
* the predicate function for each element in the array until the predicate returns a value
808-
* which is coercible to the Boolean value true, or until the end of the array.
809-
* @param thisArg An object to which the this keyword can refer in the predicate function.
810-
* If thisArg is omitted, undefined is used as the this value.
811-
*/
812-
some<This = undefined>(
813-
predicate: (
814-
this: This,
815-
value: number,
816-
index: number,
817-
array: this,
818-
) => boolean,
819-
thisArg?: This,
820-
): boolean;
821-
}
822-
823-
interface TypedNumberArrayConstructor {
824-
/**
825-
* Creates an array from an array-like or iterable object.
826-
* @param arrayLike An array-like or iterable object to convert to an array.
827-
*/
828-
from(arrayLike: ArrayLike<number>): TypedNumberArray<ArrayBuffer>;
829-
/**
830-
* Creates an array from an array-like or iterable object.
831-
* @param arrayLike An array-like or iterable object to convert to an array.
832-
* @param mapfn A mapping function to call on every element of the array.
833-
* @param thisArg Value of 'this' used to invoke the mapfn.
834-
*/
835-
from<T, This = undefined>(
836-
arrayLike: ArrayLike<T>,
837-
mapfn: (this: This, v: T, k: number) => number,
838-
thisArg?: This,
839-
): TypedNumberArray<ArrayBuffer>;
840-
}
841-
842646
/**
843647
* Construct a type with the properties of T except for those in type K.
844648
*

0 commit comments

Comments
 (0)
Please sign in to comment.