From e70f85acf55160c90d0ebcceb39a7d514d260786 Mon Sep 17 00:00:00 2001 From: uhyo Date: Sun, 16 Mar 2025 21:35:31 +0900 Subject: [PATCH 1/2] refactor: renew aliasing logic --- build/logic/ReplacementMap.ts | 41 +++ build/logic/generate.ts | 32 ++- build/logic/scanBetterFile.ts | 238 ++++++++++------- build/util/alias.ts | 112 +++++--- docs/diff/es2015.iterable.d.ts.md | 80 ++++-- docs/diff/es5.d.ts.md | 324 ++++++++++++++++++----- lib/alias.d.ts | 424 ++++++++++++++++++++++++++++++ lib/lib.es2015.iterable.d.ts | 21 -- lib/lib.es2020.bigint.d.ts | 207 --------------- lib/lib.es5.d.ts | 196 -------------- 10 files changed, 1009 insertions(+), 666 deletions(-) create mode 100644 build/logic/ReplacementMap.ts create mode 100644 lib/alias.d.ts delete mode 100644 lib/lib.es2020.bigint.d.ts diff --git a/build/logic/ReplacementMap.ts b/build/logic/ReplacementMap.ts new file mode 100644 index 0000000..e59d92e --- /dev/null +++ b/build/logic/ReplacementMap.ts @@ -0,0 +1,41 @@ +import type ts from "typescript"; + +export type ReplacementTarget = ( + | { + type: "interface"; + originalStatement: ts.InterfaceDeclaration; + members: Map< + string, + { + member: ts.TypeElement; + text: string; + }[] + >; + } + | { + type: "declare-global"; + originalStatement: ts.ModuleDeclaration; + statements: ReplacementMap; + } + | { + type: "non-interface"; + statement: ts.Statement; + } +) & { + optional: boolean; + sourceFile: ts.SourceFile; +}; + +export type ReplacementMap = Map; + +export const declareGlobalSymbol = Symbol("declare global"); +export type ReplacementName = string | typeof declareGlobalSymbol; + +export function mergeReplacementMapInto( + target: ReplacementMap, + source: ReplacementMap, +): void { + for (const [key, value] of source) { + target.set(key, [...(target.get(key) ?? []), ...value]); + } +} diff --git a/build/logic/generate.ts b/build/logic/generate.ts index 5582ad4..fe38dc2 100644 --- a/build/logic/generate.ts +++ b/build/logic/generate.ts @@ -5,11 +5,12 @@ import { upsert } from "../util/upsert"; import { getStatementDeclName } from "./ast/getStatementDeclName"; import { declareGlobalSymbol, - ReplacementMap, - ReplacementName, - ReplacementTarget, - scanBetterFile, -} from "./scanBetterFile"; + mergeReplacementMapInto, + type ReplacementMap, + type ReplacementName, + type ReplacementTarget, +} from "./ReplacementMap"; +import { loadAliasFile, scanBetterFile } from "./scanBetterFile"; type GenerateOptions = { emitOriginalAsComment?: boolean; @@ -41,6 +42,11 @@ export function generate( : ""; const replacementTargets = scanBetterFile(printer, targetFile); + const { replacementMap: aliasReplacementMap } = loadAliasFile( + printer, + targetFile, + ); + mergeReplacementMapInto(replacementTargets, aliasReplacementMap); if (replacementTargets.size === 0) { return result + originalFile.text; @@ -130,11 +136,21 @@ function generateStatements( for (const name of consumedReplacements) { replacementTargets.delete(name); } - if (replacementTargets.size > 0) { - result += "// --------------------\n"; - } + + let lineInserted = false; for (const target of replacementTargets.values()) { for (const statement of target) { + if (statement.optional) { + // Since target from aliases may not be present in the original file, + // aliases that have not been consumed are skipped. + continue; + } + + if (!lineInserted) { + result += "// --------------------\n"; + lineInserted = true; + } + if (statement.type === "non-interface") { result += statement.statement.getFullText(statement.sourceFile); } else { diff --git a/build/logic/scanBetterFile.ts b/build/logic/scanBetterFile.ts index 45908ae..2401d39 100644 --- a/build/logic/scanBetterFile.ts +++ b/build/logic/scanBetterFile.ts @@ -4,38 +4,67 @@ import { alias } from "../util/alias"; import { upsert } from "../util/upsert"; import { getStatementDeclName } from "./ast/getStatementDeclName"; import { projectDir } from "./projectDir"; +import { + declareGlobalSymbol, + type ReplacementMap, + type ReplacementName, + type ReplacementTarget, +} from "./ReplacementMap"; const betterLibDir = path.join(projectDir, "lib"); +const aliasFilePath = path.join(betterLibDir, "alias.d.ts"); -export type ReplacementTarget = ( - | { - type: "interface"; - originalStatement: ts.InterfaceDeclaration; - members: Map< - string, - { - member: ts.TypeElement; - text: string; - }[] - >; - } - | { - type: "declare-global"; - originalStatement: ts.ModuleDeclaration; - statements: ReplacementMap; +type AliasFile = { + replacementMap: ReplacementMap; +}; + +// Cache for alias file statements +let aliasFileCache: ts.SourceFile | undefined; + +/** + * Load the alias file applied to the target file. + */ +export function loadAliasFile( + printer: ts.Printer, + targetFileName: string, +): AliasFile { + if (!aliasFileCache) { + const aliasProgram = ts.createProgram([aliasFilePath], {}); + const aliasFile = aliasProgram.getSourceFile(aliasFilePath); + + if (!aliasFile) { + throw new Error("Alias file not found in the program"); } - | { - type: "non-interface"; - statement: ts.Statement; + aliasFileCache = aliasFile; + } + const aliasFile = aliasFileCache; + const statements = aliasFile.statements.flatMap((statement) => { + const name = getStatementDeclName(statement) ?? ""; + const aliases = alias.get(name); + if (!aliases) { + return [statement]; } -) & { - sourceFile: ts.SourceFile; -}; + return aliases.map((aliasDetails) => { + if (aliasDetails.file !== targetFileName) { + return statement; + } + return replaceAliases(statement, aliasDetails.replacement); + }); + }); -export type ReplacementMap = Map; + // Scan the target file + const replacementMap = scanStatements(printer, statements, aliasFile); + // mark everything as optional + for (const targets of replacementMap.values()) { + for (const target of targets) { + target.optional = true; + } + } -export const declareGlobalSymbol = Symbol("declare global"); -export type ReplacementName = string | typeof declareGlobalSymbol; + return { + replacementMap, + }; +} /** * Scan better lib file to determine which statements need to be replaced. @@ -56,83 +85,82 @@ export function scanBetterFile( function scanStatements( printer: ts.Printer, - statements: ts.NodeArray, + statements: readonly ts.Statement[], sourceFile: ts.SourceFile, ): ReplacementMap { const replacementTargets = new Map(); for (const statement of statements) { const name = getStatementDeclName(statement) ?? ""; - const aliasesMap = - alias.get(name) ?? new Map([[name, new Map()]]); - for (const [targetName, typeMap] of aliasesMap) { - const transformedStatement = replaceAliases(statement, typeMap); - if (ts.isInterfaceDeclaration(transformedStatement)) { - const members = new Map< - string, - { - member: ts.TypeElement; - text: string; - }[] - >(); - for (const member of transformedStatement.members) { - const memberName = member.name?.getText(sourceFile) ?? ""; - upsert(members, memberName, (members = []) => { - const leadingSpacesMatch = /^\s*/.exec( - member.getFullText(sourceFile), - ); - const leadingSpaces = - leadingSpacesMatch !== null ? leadingSpacesMatch[0] : ""; - members.push({ - member, - text: - leadingSpaces + - printer.printNode(ts.EmitHint.Unspecified, member, sourceFile), - }); - return members; - }); - } - upsert(replacementTargets, targetName, (targets = []) => { - targets.push({ - type: "interface", - members, - originalStatement: transformedStatement, - sourceFile: sourceFile, + const transformedStatement = statement; + if (ts.isInterfaceDeclaration(transformedStatement)) { + const members = new Map< + string, + { + member: ts.TypeElement; + text: string; + }[] + >(); + for (const member of transformedStatement.members) { + const memberName = member.name?.getText(sourceFile) ?? ""; + upsert(members, memberName, (members = []) => { + const leadingSpacesMatch = /^\s*/.exec( + member.getFullText(sourceFile), + ); + const leadingSpaces = + leadingSpacesMatch !== null ? leadingSpacesMatch[0] : ""; + members.push({ + member, + text: + leadingSpaces + + printer.printNode(ts.EmitHint.Unspecified, member, sourceFile), }); - return targets; + return members; }); - } else if ( - ts.isModuleDeclaration(transformedStatement) && - ts.isIdentifier(transformedStatement.name) && - transformedStatement.name.text === "global" - ) { - // declare global - upsert(replacementTargets, declareGlobalSymbol, (targets = []) => { - targets.push({ - type: "declare-global", - originalStatement: transformedStatement, - statements: - transformedStatement.body && - ts.isModuleBlock(transformedStatement.body) - ? scanStatements( - printer, - transformedStatement.body.statements, - sourceFile, - ) - : new Map(), - sourceFile: sourceFile, - }); - return targets; + } + upsert(replacementTargets, name, (targets = []) => { + targets.push({ + type: "interface", + members, + originalStatement: transformedStatement, + optional: false, + sourceFile: sourceFile, }); - } else { - upsert(replacementTargets, targetName, (statements = []) => { - statements.push({ - type: "non-interface", - statement: transformedStatement, - sourceFile: sourceFile, - }); - return statements; + return targets; + }); + } else if ( + ts.isModuleDeclaration(transformedStatement) && + ts.isIdentifier(transformedStatement.name) && + transformedStatement.name.text === "global" + ) { + // declare global + upsert(replacementTargets, declareGlobalSymbol, (targets = []) => { + targets.push({ + type: "declare-global", + originalStatement: transformedStatement, + statements: + transformedStatement.body && + ts.isModuleBlock(transformedStatement.body) + ? scanStatements( + printer, + transformedStatement.body.statements, + sourceFile, + ) + : new Map(), + optional: false, + sourceFile: sourceFile, }); - } + return targets; + }); + } else { + upsert(replacementTargets, name, (statements = []) => { + statements.push({ + type: "non-interface", + statement: transformedStatement, + optional: false, + sourceFile: sourceFile, + }); + return statements; + }); } } return replacementTargets; @@ -140,20 +168,34 @@ function scanStatements( function replaceAliases( statement: ts.Statement, - typeMap: Map, + replacement: Map, ): ts.Statement { - if (typeMap.size === 0) return statement; return ts.transform(statement, [ (context) => (sourceStatement) => { const visitor = (node: ts.Node): ts.Node => { + if (ts.isInterfaceDeclaration(node)) { + const toName = replacement.get(node.name.text); + if (toName === undefined) { + return node; + } + const visited = ts.visitEachChild(node, visitor, context); + return ts.factory.updateInterfaceDeclaration( + visited, + visited.modifiers, + ts.factory.createIdentifier(toName), + visited.typeParameters, + visited.heritageClauses, + visited.members, + ); + } if (ts.isTypeReferenceNode(node) && ts.isIdentifier(node.typeName)) { - const replacementType = typeMap.get(node.typeName.text); - if (replacementType === undefined) { + const toName = replacement.get(node.typeName.text); + if (toName === undefined) { return node; } return ts.factory.updateTypeReferenceNode( node, - ts.factory.createIdentifier(replacementType), + ts.factory.createIdentifier(toName), node.typeArguments, ); } diff --git a/build/util/alias.ts b/build/util/alias.ts index ba731eb..247b78a 100644 --- a/build/util/alias.ts +++ b/build/util/alias.ts @@ -1,46 +1,72 @@ -const aliasArray: [string, string[]][] = [ +export type AliasDetails = { + /** + * File to which this alias applies. + */ + file: string; + /** + * Needed replacement. + */ + replacement: Map; +}; + +const es5TypedArrays = [ + "Int8Array", + "Uint8Array", + "Uint8ClampedArray", + "Int16Array", + "Uint16Array", + "Int32Array", + "Uint32Array", + "Float32Array", + "Float64Array", + "Float16Array", +]; + +const es2020TypedBigIntArrays = ["BigInt64Array", "BigUint64Array"]; + +export const alias = new Map([ [ "TypedNumberArray", - [ - "Int8Array", - "Uint8Array", - "Uint8ClampedArray", - "Int16Array", - "Uint16Array", - "Int32Array", - "Uint32Array", - "Float32Array", - "Float64Array", - ], + es5TypedArrays.map((name) => ({ + file: "lib.es5.d.ts", + replacement: new Map([["TypedNumberArray", name]]), + })), ], - ["TypedBigIntArray", ["BigInt64Array", "BigUint64Array"]], -]; - -export const alias = new Map( - aliasArray.flatMap(([originalType, replacementTypes]) => [ - [ - originalType, - new Map( - replacementTypes.map((replacement) => [ - replacement, - new Map([ - [originalType, replacement], - [`${originalType}Constructor`, `${replacement}Constructor`], - ]), - ]), - ), - ], - [ - `${originalType}Constructor`, - new Map( - replacementTypes.map((replacement) => [ - `${replacement}Constructor`, - new Map([ - [originalType, replacement], - [`${originalType}Constructor`, `${replacement}Constructor`], - ]), - ]), - ), - ], - ]), -); + [ + "TypedNumberArrayConstructor", + es5TypedArrays.map((name) => ({ + file: "lib.es5.d.ts", + replacement: new Map([ + ["TypedNumberArray", name], + ["TypedNumberArrayConstructor", `${name}Constructor`], + ]), + })), + ], + [ + "TypedNumberArrayConstructorIter", + es5TypedArrays.map((name) => ({ + file: "lib.es2015.iterable.d.ts", + replacement: new Map([ + ["TypedNumberArray", name], + ["TypedNumberArrayConstructorIter", `${name}Constructor`], + ]), + })), + ], + [ + "TypedBigIntArray", + es2020TypedBigIntArrays.map((name) => ({ + file: "lib.es2020.bigint.d.ts", + replacement: new Map([["TypedBigIntArray", name]]), + })), + ], + [ + "TypedBigIntArrayConstructor", + es2020TypedBigIntArrays.map((name) => ({ + file: "lib.es2020.bigint.d.ts", + replacement: new Map([ + ["TypedBigIntArray", name], + ["TypedBigIntArrayConstructor", `${name}Constructor`], + ]), + })), + ], +]); diff --git a/docs/diff/es2015.iterable.d.ts.md b/docs/diff/es2015.iterable.d.ts.md index d57b79d..4312e49 100644 --- a/docs/diff/es2015.iterable.d.ts.md +++ b/docs/diff/es2015.iterable.d.ts.md @@ -6,7 +6,7 @@ Index: es2015.iterable.d.ts --- es2015.iterable.d.ts +++ es2015.iterable.d.ts @@ -20,24 +20,23 @@ - + type IteratorResult = | IteratorYieldResult | IteratorReturnResult; @@ -18,12 +18,12 @@ Index: es2015.iterable.d.ts return?(value?: TReturn): IteratorResult; throw?(e?: any): IteratorResult; } - + -interface Iterable { +interface Iterable { [Symbol.iterator](): Iterator; } - + /** * Describes a user-defined {@link Iterator} that is also iterable. */ @@ -32,7 +32,7 @@ Index: es2015.iterable.d.ts extends Iterator { [Symbol.iterator](): IterableIterator; } - + @@ -92,12 +91,12 @@ * @param iterable An iterable object to convert to an array. * @param mapfn A mapping function to call on every element of the array. @@ -47,28 +47,28 @@ Index: es2015.iterable.d.ts + thisArg?: This, ): U[]; } - + interface ReadonlyArray { @@ -121,9 +120,9 @@ } - + interface IArguments { /** Iterator */ - [Symbol.iterator](): ArrayIterator; + [Symbol.iterator](): ArrayIterator; } - + interface MapIterator extends IteratorObject { @@ -170,9 +169,8 @@ values(): MapIterator; } - + interface MapConstructor { - new (): Map; new (iterable?: Iterable | null): Map; } - + interface WeakMap {} @@ -244,17 +242,17 @@ * resolve, or rejected when any Promise is rejected. @@ -77,7 +77,7 @@ Index: es2015.iterable.d.ts */ - all(values: Iterable>): Promise[]>; + all(values: Iterable): Promise[]>; - + /** * Creates a Promise that is resolved or rejected when any of the provided Promises are resolved * or rejected. @@ -87,12 +87,12 @@ Index: es2015.iterable.d.ts - race(values: Iterable>): Promise>; + race(values: Iterable): Promise>; } - + interface StringIterator extends IteratorObject { @@ -283,26 +281,23 @@ } - + interface Int8ArrayConstructor { new (elements: Iterable): Int8Array; - @@ -124,11 +124,11 @@ Index: es2015.iterable.d.ts + thisArg?: This, ): Int8Array; } - + interface Uint8Array { @@ -322,26 +317,23 @@ } - + interface Uint8ArrayConstructor { new (elements: Iterable): Uint8Array; - @@ -160,11 +160,11 @@ Index: es2015.iterable.d.ts + thisArg?: This, ): Uint8Array; } - + interface Uint8ClampedArray { @@ -363,26 +355,25 @@ } - + interface Uint8ClampedArrayConstructor { new (elements: Iterable): Uint8ClampedArray; - @@ -198,11 +198,11 @@ Index: es2015.iterable.d.ts + thisArg?: This, ): Uint8ClampedArray; } - + interface Int16Array { @@ -404,26 +395,23 @@ } - + interface Int16ArrayConstructor { new (elements: Iterable): Int16Array; - @@ -234,11 +234,11 @@ Index: es2015.iterable.d.ts + thisArg?: This, ): Int16Array; } - + interface Uint16Array { @@ -443,26 +431,25 @@ } - + interface Uint16ArrayConstructor { new (elements: Iterable): Uint16Array; - @@ -272,11 +272,11 @@ Index: es2015.iterable.d.ts + thisArg?: This, ): Uint16Array; } - + interface Int32Array { @@ -482,26 +469,23 @@ } - + interface Int32ArrayConstructor { new (elements: Iterable): Int32Array; - @@ -308,11 +308,11 @@ Index: es2015.iterable.d.ts + thisArg?: This, ): Int32Array; } - + interface Uint32Array { @@ -521,26 +505,25 @@ } - + interface Uint32ArrayConstructor { new (elements: Iterable): Uint32Array; - @@ -346,11 +346,11 @@ Index: es2015.iterable.d.ts + thisArg?: This, ): Uint32Array; } - + interface Float32Array { @@ -560,26 +543,25 @@ } - + interface Float32ArrayConstructor { new (elements: Iterable): Float32Array; - @@ -384,11 +384,11 @@ Index: es2015.iterable.d.ts + thisArg?: This, ): Float32Array; } - + interface Float64Array { -@@ -599,24 +581,23 @@ +@@ -615,23 +605,45 @@ } - + interface Float64ArrayConstructor { new (elements: Iterable): Float64Array; - @@ -422,5 +422,27 @@ Index: es2015.iterable.d.ts + thisArg?: This, ): Float64Array; } ++// -------------------- ++ ++interface TypedNumberArrayConstructor { ++ /** ++ * Creates an array from an iterable object. ++ * @param iterable An iterable object to convert to an array. ++ */ ++ from( ++ iterable: Iterable | ArrayLike, ++ ): TypedNumberArray; ++ /** ++ * Creates an array from an iterable object. ++ * @param iterable An iterable object to convert to an array. ++ * @param mapfn A mapping function to call on every element of the array. ++ * @param thisArg Value of 'this' used to invoke the mapfn. ++ */ ++ from( ++ iterable: Iterable | ArrayLike, ++ mapfn: (this: This, v: T, k: number) => number, ++ thisArg?: This, ++ ): TypedNumberArray; ++} ``` diff --git a/docs/diff/es5.d.ts.md b/docs/diff/es5.d.ts.md index 3ed6956..0e6d77f 100644 --- a/docs/diff/es5.d.ts.md +++ b/docs/diff/es5.d.ts.md @@ -12,13 +12,13 @@ Index: es5.d.ts */ -declare function eval(x: string): any; +declare function eval(x: string): unknown; - + /** * Converts a string to an integer. * @param string A string to convert into a number. @@ -115,14 +115,27 @@ toLocaleString(): string; - + /** Returns the primitive value of the specified object. */ valueOf(): Object; - @@ -42,30 +42,30 @@ Index: es5.d.ts + [key in Key]: unknown; + } + : {}); - + /** * Determines whether an object exists in another object's prototype chain. * @param v Another object whose prototype chain is to be checked. @@ -137,75 +150,145 @@ } - + interface ObjectConstructor { new (value?: any): Object; - (): any; - (value: any): any; + (): {}; + (value: T): T extends object ? T : {}; - + /** A reference to the prototype for a class of objects. */ readonly prototype: Object; - + /** * Returns the prototype of an object. * @param o The object that references the prototype. */ - getPrototypeOf(o: any): any; + getPrototypeOf(o: {}): unknown; - + /** * Gets the own property descriptor of the specified object. * An own property descriptor is one that is defined directly on the object and is not inherited from the object's prototype. @@ -77,7 +77,7 @@ Index: es5.d.ts + o: {}, p: PropertyKey, ): PropertyDescriptor | undefined; - + /** * Returns the names of the own properties of an object. The own properties of an object are those that are defined directly * on that object, and are not inherited from the object's prototype. The properties of an object include both fields (objects) and functions. @@ -85,14 +85,14 @@ Index: es5.d.ts */ - getOwnPropertyNames(o: any): string[]; + getOwnPropertyNames(o: {}): string[]; - + /** * Creates an object that has the specified prototype or that has null prototype. * @param o Object to use as a prototype. May be null. */ - create(o: object | null): any; + create(o: O): O; - + /** + * Creates an object that has the specified prototype or that has null prototype. + * @param o Object to use as a prototype. May be null. @@ -124,7 +124,7 @@ Index: es5.d.ts + ? O[K] + : unknown; + }; - + /** + * Creates an object that has the specified prototype, and that optionally contains specified properties. + * @param o Object to use as a prototype. May be null @@ -178,7 +178,7 @@ Index: es5.d.ts + : unknown; + } + : unknown); - + /** * Adds one or more properties to an object, and/or modifies attributes of existing properties. * @param o Object on which to add or modify the properties. This can be a native JavaScript object or a DOM object. @@ -207,7 +207,7 @@ Index: es5.d.ts + ? O[K] + : unknown; + }; - + /** * Prevents the modification of attributes of existing properties, and prevents the addition of new properties. * @param o Object on which to lock the attributes. @@ -254,14 +254,14 @@ Index: es5.d.ts ...args: A ): new (...args: B) => R; } - + interface IArguments { - [index: number]: any; + [index: number]: unknown; length: number; callee: Function; } - + @@ -486,24 +567,28 @@ * Matches a string with a regular expression, and returns an array containing the results of that search. * @param regexp A variable name or string literal containing the regular expression pattern and flags. @@ -276,7 +276,7 @@ Index: es5.d.ts + * @param replaceValue A string containing the text to replace for every successful match of searchValue in this string. */ replace(searchValue: string | RegExp, replaceValue: string): string; - + /** * Replaces text in a string, using a regular expression or search string. - * @param searchValue A string to search for. @@ -293,7 +293,7 @@ Index: es5.d.ts + ...rest: (string | number)[] + ) => string, ): string; - + /** * Finds the first substring match in a regular expression search. @@ -1200,37 +1285,71 @@ @@ -378,7 +378,7 @@ Index: es5.d.ts + space?: string | number | null | undefined, + ): string | undefined; } - + /** * An intrinsic object that provides functions to convert JavaScript values to and from the JavaScript Object Notation (JSON) format. @@ -1294,23 +1413,25 @@ @@ -566,7 +566,7 @@ Index: es5.d.ts ) => U, initialValue: U, ): U; - + @@ -1552,23 +1658,25 @@ * which is coercible to the Boolean value false, or until the end of the array. * @param thisArg An object to which the this keyword can refer in the predicate function. @@ -752,10 +752,10 @@ Index: es5.d.ts ) => U, initialValue: U, ): U; - + [n: number]: T; } - + interface ArrayConstructor { - new (arrayLength?: number): any[]; new (arrayLength: number): T[]; @@ -768,12 +768,12 @@ Index: es5.d.ts + isArray(arg: any): arg is unknown[]; + readonly prototype: unknown[]; } - + declare var Array: ArrayConstructor; - + @@ -1716,9 +1807,11 @@ } - + declare type PromiseConstructorLike = new ( executor: ( - resolve: (value: T | PromiseLike) => void, @@ -783,7 +783,7 @@ Index: es5.d.ts reject: (reason?: any) => void, ) => void, ) => PromiseLike; - + @@ -1728,52 +1821,56 @@ * @param onfulfilled The callback to execute when the Promise is resolved. * @param onrejected The callback to execute when the Promise is rejected. @@ -815,7 +815,7 @@ Index: es5.d.ts + onrejected?: ((reason: unknown) => U | PromiseLike) | null | undefined, + ): PromiseLike; } - + -/** - * Represents the completion of an asynchronous operation - */ @@ -841,7 +841,7 @@ Index: es5.d.ts + onfulfilled: (value: T) => U | PromiseLike, + onrejected?: ((reason: unknown) => U | PromiseLike) | null | undefined, + ): Promise; - + /** + * Attaches callbacks for the resolution and/or rejection of the Promise. + * @param onfulfilled The callback to execute when the Promise is resolved. @@ -868,12 +868,12 @@ Index: es5.d.ts + onrejected: ((reason: unknown) => U | PromiseLike) | null | undefined, + ): Promise; } - + /** * Recursively unwraps the "awaited type" of a type. Non-promise "thenables" should resolve to `never`. This emulates the behavior of `await`. @@ -1837,8 +1934,11 @@ type Extract = T extends U ? T : never; - + /** * Construct a type with the properties of T except for those in type K. + * @@ -881,7 +881,7 @@ Index: es5.d.ts + * @see {@link https://github.com/microsoft/TypeScript/issues/54451} */ type Omit = Pick>; - + /** @@ -2138,20 +2238,24 @@ * is treated as length+end. @@ -909,7 +909,7 @@ Index: es5.d.ts + ) => boolean, + thisArg?: This, ): boolean; - + /** * Changes all array elements from `start` to `end` index to a static `value` and returns the modified array @@ -2161,21 +2265,24 @@ @@ -987,7 +987,7 @@ Index: es5.d.ts + callbackfn: (this: This, value: number, index: number, array: this) => void, + thisArg?: This, ): void; - + /** * Returns the index of the first occurrence of a value in an array. @@ -2241,50 +2346,40 @@ @@ -1143,7 +1143,7 @@ Index: es5.d.ts + ) => boolean, + thisArg?: This, ): boolean; - + /** * Sorts an array. @@ -2438,25 +2523,23 @@ @@ -1174,7 +1174,7 @@ Index: es5.d.ts ): Int8Array; } declare var Int8Array: Int8ArrayConstructor; - + @@ -2494,20 +2577,24 @@ * is treated as length+end. * @param end If not specified, length of the this object is used as its default value. @@ -1201,7 +1201,7 @@ Index: es5.d.ts + ) => boolean, + thisArg?: This, ): boolean; - + /** * Changes all array elements from `start` to `end` index to a static `value` and returns the modified array @@ -2517,21 +2604,24 @@ @@ -1279,7 +1279,7 @@ Index: es5.d.ts + callbackfn: (this: This, value: number, index: number, array: this) => void, + thisArg?: This, ): void; - + /** * Returns the index of the first occurrence of a value in an array. @@ -2597,50 +2685,40 @@ @@ -1435,7 +1435,7 @@ Index: es5.d.ts + ) => boolean, + thisArg?: This, ): boolean; - + /** * Sorts an array. @@ -2794,25 +2862,23 @@ @@ -1466,7 +1466,7 @@ Index: es5.d.ts ): Uint8Array; } declare var Uint8Array: Uint8ArrayConstructor; - + @@ -2852,20 +2918,24 @@ * is treated as length+end. * @param end If not specified, length of the this object is used as its default value. @@ -1493,7 +1493,7 @@ Index: es5.d.ts + ) => boolean, + thisArg?: This, ): boolean; - + /** * Changes all array elements from `start` to `end` index to a static `value` and returns the modified array @@ -2875,21 +2945,24 @@ @@ -1571,7 +1571,7 @@ Index: es5.d.ts + callbackfn: (this: This, value: number, index: number, array: this) => void, + thisArg?: This, ): void; - + /** * Returns the index of the first occurrence of a value in an array. @@ -2955,50 +3026,40 @@ @@ -1727,7 +1727,7 @@ Index: es5.d.ts + ) => boolean, + thisArg?: This, ): boolean; - + /** * Sorts an array. @@ -3152,25 +3203,23 @@ @@ -1758,7 +1758,7 @@ Index: es5.d.ts ): Uint8ClampedArray; } declare var Uint8ClampedArray: Uint8ClampedArrayConstructor; - + @@ -3208,20 +3257,24 @@ * is treated as length+end. * @param end If not specified, length of the this object is used as its default value. @@ -1785,7 +1785,7 @@ Index: es5.d.ts + ) => boolean, + thisArg?: This, ): boolean; - + /** * Changes all array elements from `start` to `end` index to a static `value` and returns the modified array @@ -3231,21 +3284,24 @@ @@ -2019,7 +2019,7 @@ Index: es5.d.ts + ) => boolean, + thisArg?: This, ): boolean; - + /** * Sorts an array. @@ -3507,25 +3541,23 @@ @@ -2050,7 +2050,7 @@ Index: es5.d.ts ): Int16Array; } declare var Int16Array: Int16ArrayConstructor; - + @@ -3563,20 +3595,24 @@ * is treated as length+end. * @param end If not specified, length of the this object is used as its default value. @@ -2077,7 +2077,7 @@ Index: es5.d.ts + ) => boolean, + thisArg?: This, ): boolean; - + /** * Changes all array elements from `start` to `end` index to a static `value` and returns the modified array @@ -3586,21 +3622,24 @@ @@ -2155,7 +2155,7 @@ Index: es5.d.ts + callbackfn: (this: This, value: number, index: number, array: this) => void, + thisArg?: This, ): void; - + /** * Returns the index of the first occurrence of a value in an array. @@ -3666,50 +3703,40 @@ @@ -2311,7 +2311,7 @@ Index: es5.d.ts + ) => boolean, + thisArg?: This, ): boolean; - + /** * Sorts an array. @@ -3863,25 +3880,23 @@ @@ -2369,7 +2369,7 @@ Index: es5.d.ts + ) => boolean, + thisArg?: This, ): boolean; - + /** * Changes all array elements from `start` to `end` index to a static `value` and returns the modified array @@ -3941,21 +3960,24 @@ @@ -2447,7 +2447,7 @@ Index: es5.d.ts + callbackfn: (this: This, value: number, index: number, array: this) => void, + thisArg?: This, ): void; - + /** * Returns the index of the first occurrence of a value in an array. @@ -4021,50 +4041,40 @@ @@ -2603,7 +2603,7 @@ Index: es5.d.ts + ) => boolean, + thisArg?: This, ): boolean; - + /** * Sorts an array. @@ -4218,25 +4218,23 @@ @@ -2634,7 +2634,7 @@ Index: es5.d.ts ): Int32Array; } declare var Int32Array: Int32ArrayConstructor; - + @@ -4274,20 +4272,24 @@ * is treated as length+end. * @param end If not specified, length of the this object is used as its default value. @@ -2661,7 +2661,7 @@ Index: es5.d.ts + ) => boolean, + thisArg?: This, ): boolean; - + /** * Changes all array elements from `start` to `end` index to a static `value` and returns the modified array @@ -4297,21 +4299,24 @@ @@ -2895,7 +2895,7 @@ Index: es5.d.ts + ) => boolean, + thisArg?: This, ): boolean; - + /** * Sorts an array. @@ -4573,25 +4556,23 @@ @@ -2926,7 +2926,7 @@ Index: es5.d.ts ): Uint32Array; } declare var Uint32Array: Uint32ArrayConstructor; - + @@ -4629,20 +4610,24 @@ * is treated as length+end. * @param end If not specified, length of the this object is used as its default value. @@ -2953,7 +2953,7 @@ Index: es5.d.ts + ) => boolean, + thisArg?: This, ): boolean; - + /** * Changes all array elements from `start` to `end` index to a static `value` and returns the modified array @@ -4652,21 +4637,24 @@ @@ -3031,7 +3031,7 @@ Index: es5.d.ts + callbackfn: (this: This, value: number, index: number, array: this) => void, + thisArg?: This, ): void; - + /** * Returns the index of the first occurrence of a value in an array. @@ -4732,50 +4718,40 @@ @@ -3187,7 +3187,7 @@ Index: es5.d.ts + ) => boolean, + thisArg?: This, ): boolean; - + /** * Sorts an array. @@ -4929,25 +4895,23 @@ @@ -3218,7 +3218,7 @@ Index: es5.d.ts ): Float32Array; } declare var Float32Array: Float32ArrayConstructor; - + @@ -4985,20 +4949,24 @@ * is treated as length+end. * @param end If not specified, length of the this object is used as its default value. @@ -3245,7 +3245,7 @@ Index: es5.d.ts + ) => boolean, + thisArg?: This, ): boolean; - + /** * Changes all array elements from `start` to `end` index to a static `value` and returns the modified array @@ -5008,21 +4976,24 @@ @@ -3323,7 +3323,7 @@ Index: es5.d.ts + callbackfn: (this: This, value: number, index: number, array: this) => void, + thisArg?: This, ): void; - + /** * Returns the index of the first occurrence of a value in an array. @@ -5088,50 +5057,40 @@ @@ -3479,7 +3479,7 @@ Index: es5.d.ts + ) => boolean, + thisArg?: This, ): boolean; - + /** * Sorts an array. @@ -5285,25 +5234,23 @@ @@ -3510,8 +3510,8 @@ Index: es5.d.ts ): Float64Array; } declare var Float64Array: Float64ArrayConstructor; - -@@ -5564,4 +5511,33 @@ + +@@ -5609,4 +5556,229 @@ locales?: string | string[], options?: Intl.DateTimeFormatOptions, ): string; @@ -3545,5 +3545,201 @@ Index: es5.d.ts +type UndefinedDomain = symbol | SomeFunction | SomeConstructor | undefined; +type StringifyResultT = A extends UndefinedDomain ? undefined : string; +type StringifyResult = StringifyResultT | SomeExtends; ++ ++interface TypedNumberArray< ++ TArrayBuffer extends ArrayBufferLike = ArrayBufferLike, ++> { ++ /** ++ * Determines whether all the members of an array satisfy the specified test. ++ * @param predicate A function that accepts up to three arguments. The every method calls ++ * the predicate function for each element in the array until the predicate returns a value ++ * which is coercible to the Boolean value false, or until the end of the array. ++ * @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. ++ */ ++ every( ++ predicate: ( ++ this: This, ++ value: number, ++ index: number, ++ array: this, ++ ) => boolean, ++ thisArg?: This, ++ ): boolean; ++ /** ++ * Returns the elements of an array that meet the condition specified in a callback function. ++ * @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. ++ * @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. ++ */ ++ filter( ++ predicate: ( ++ this: This, ++ value: number, ++ index: number, ++ array: this, ++ ) => boolean, ++ thisArg?: This, ++ ): TypedNumberArray; ++ /** ++ * Returns the value of the first element in the array where predicate is true, and undefined ++ * otherwise. ++ * @param predicate find calls predicate once for each element of the array, in ascending ++ * order, until it finds one where predicate returns true. If such an element is found, find ++ * immediately returns that element value. Otherwise, find returns undefined. ++ * @param thisArg If provided, it will be used as the this value for each invocation of ++ * predicate. If it is not provided, undefined is used instead. ++ */ ++ find( ++ predicate: (this: This, value: number, index: number, obj: this) => boolean, ++ thisArg?: This, ++ ): number | undefined; ++ /** ++ * Returns the index of the first element in the array where predicate is true, and -1 ++ * otherwise. ++ * @param predicate find calls predicate once for each element of the array, in ascending ++ * order, until it finds one where predicate returns true. If such an element is found, ++ * findIndex immediately returns that element index. Otherwise, findIndex returns -1. ++ * @param thisArg If provided, it will be used as the this value for each invocation of ++ * predicate. If it is not provided, undefined is used instead. ++ */ ++ findIndex( ++ predicate: (this: This, value: number, index: number, obj: this) => boolean, ++ thisArg?: This, ++ ): number; ++ /** ++ * Performs the specified action for each element in an array. ++ * @param callbackfn A function that accepts up to three arguments. forEach calls the ++ * callbackfn function one time for each element in the array. ++ * @param thisArg An object to which the this keyword can refer in the callbackfn function. ++ * If thisArg is omitted, undefined is used as the this value. ++ */ ++ forEach( ++ callbackfn: (this: This, value: number, index: number, array: this) => void, ++ thisArg?: This, ++ ): void; ++ /** ++ * Calls a defined callback function on each element of an array, and returns an array that ++ * contains the results. ++ * @param callbackfn A function that accepts up to three arguments. The map method calls the ++ * callbackfn function one time for each element in the array. ++ * @param thisArg An object to which the this keyword can refer in the callbackfn function. ++ * If thisArg is omitted, undefined is used as the this value. ++ */ ++ map( ++ callbackfn: ( ++ this: This, ++ value: number, ++ index: number, ++ array: this, ++ ) => number, ++ thisArg?: This, ++ ): TypedNumberArray; ++ /** ++ * Calls the specified callback function for all the elements in an array. The return value of ++ * the callback function is the accumulated result, and is provided as an argument in the next ++ * call to the callback function. ++ * @param callbackfn A function that accepts up to four arguments. The reduce method calls the ++ * callbackfn function one time for each element in the array. ++ */ ++ reduce( ++ callbackfn: ( ++ previousValue: number | U, ++ currentValue: number, ++ currentIndex: number, ++ array: this, ++ ) => U, ++ ): number | U; ++ /** ++ * Calls the specified callback function for all the elements in an array. The return value of ++ * the callback function is the accumulated result, and is provided as an argument in the next ++ * call to the callback function. ++ * @param callbackfn A function that accepts up to four arguments. The reduce method calls the ++ * callbackfn function one time for each element in the array. ++ * @param initialValue If initialValue is specified, it is used as the initial value to start ++ * the accumulation. The first call to the callbackfn function provides this value as an argument ++ * instead of an array value. ++ */ ++ reduce( ++ callbackfn: ( ++ previousValue: U, ++ currentValue: number, ++ currentIndex: number, ++ array: this, ++ ) => U, ++ initialValue: U, ++ ): U; ++ /** ++ * Calls the specified callback function for all the elements in an array, in descending order. ++ * The return value of the callback function is the accumulated result, and is provided as an ++ * argument in the next call to the callback function. ++ * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls ++ * the callbackfn function one time for each element in the array. ++ */ ++ reduceRight( ++ callbackfn: ( ++ previousValue: number | U, ++ currentValue: number, ++ currentIndex: number, ++ array: this, ++ ) => U, ++ ): number | U; ++ /** ++ * Calls the specified callback function for all the elements in an array, in descending order. ++ * The return value of the callback function is the accumulated result, and is provided as an ++ * argument in the next call to the callback function. ++ * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls ++ * the callbackfn function one time for each element in the array. ++ * @param initialValue If initialValue is specified, it is used as the initial value to start ++ * the accumulation. The first call to the callbackfn function provides this value as an argument ++ * instead of an array value. ++ */ ++ reduceRight( ++ callbackfn: ( ++ previousValue: U, ++ currentValue: number, ++ currentIndex: number, ++ array: this, ++ ) => U, ++ initialValue: U, ++ ): U; ++ /** ++ * Determines whether the specified callback function returns true for any element of an array. ++ * @param predicate A function that accepts up to three arguments. The some method calls ++ * the predicate function for each element in the array until the predicate returns a value ++ * which is coercible to the Boolean value true, or until the end of the array. ++ * @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. ++ */ ++ some( ++ predicate: ( ++ this: This, ++ value: number, ++ index: number, ++ array: this, ++ ) => boolean, ++ thisArg?: This, ++ ): boolean; ++} ++ ++interface TypedNumberArrayConstructor { ++ /** ++ * Creates an array from an array-like or iterable object. ++ * @param arrayLike An array-like or iterable object to convert to an array. ++ */ ++ from(arrayLike: ArrayLike): TypedNumberArray; ++ /** ++ * Creates an array from an array-like or iterable object. ++ * @param arrayLike An array-like or iterable object to convert to an array. ++ * @param mapfn A mapping function to call on every element of the array. ++ * @param thisArg Value of 'this' used to invoke the mapfn. ++ */ ++ from( ++ arrayLike: ArrayLike, ++ mapfn: (this: This, v: T, k: number) => number, ++ thisArg?: This, ++ ): TypedNumberArray; ++} ``` diff --git a/lib/alias.d.ts b/lib/alias.d.ts new file mode 100644 index 0000000..8236852 --- /dev/null +++ b/lib/alias.d.ts @@ -0,0 +1,424 @@ +interface TypedNumberArray< + TArrayBuffer extends ArrayBufferLike = ArrayBufferLike, +> { + /** + * Determines whether all the members of an array satisfy the specified test. + * @param predicate A function that accepts up to three arguments. The every method calls + * the predicate function for each element in the array until the predicate returns a value + * which is coercible to the Boolean value false, or until the end of the array. + * @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. + */ + every( + predicate: ( + this: This, + value: number, + index: number, + array: this, + ) => boolean, + thisArg?: This, + ): boolean; + /** + * Returns the elements of an array that meet the condition specified in a callback function. + * @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. + * @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. + */ + filter( + predicate: ( + this: This, + value: number, + index: number, + array: this, + ) => boolean, + thisArg?: This, + ): TypedNumberArray; + /** + * Returns the value of the first element in the array where predicate is true, and undefined + * otherwise. + * @param predicate find calls predicate once for each element of the array, in ascending + * order, until it finds one where predicate returns true. If such an element is found, find + * immediately returns that element value. Otherwise, find returns undefined. + * @param thisArg If provided, it will be used as the this value for each invocation of + * predicate. If it is not provided, undefined is used instead. + */ + find( + predicate: (this: This, value: number, index: number, obj: this) => boolean, + thisArg?: This, + ): number | undefined; + /** + * Returns the index of the first element in the array where predicate is true, and -1 + * otherwise. + * @param predicate find calls predicate once for each element of the array, in ascending + * order, until it finds one where predicate returns true. If such an element is found, + * findIndex immediately returns that element index. Otherwise, findIndex returns -1. + * @param thisArg If provided, it will be used as the this value for each invocation of + * predicate. If it is not provided, undefined is used instead. + */ + findIndex( + predicate: (this: This, value: number, index: number, obj: this) => boolean, + thisArg?: This, + ): number; + /** + * Performs the specified action for each element in an array. + * @param callbackfn A function that accepts up to three arguments. forEach calls the + * callbackfn function one time for each element in the array. + * @param thisArg An object to which the this keyword can refer in the callbackfn function. + * If thisArg is omitted, undefined is used as the this value. + */ + forEach( + callbackfn: (this: This, value: number, index: number, array: this) => void, + thisArg?: This, + ): void; + /** + * Calls a defined callback function on each element of an array, and returns an array that + * contains the results. + * @param callbackfn A function that accepts up to three arguments. The map method calls the + * callbackfn function one time for each element in the array. + * @param thisArg An object to which the this keyword can refer in the callbackfn function. + * If thisArg is omitted, undefined is used as the this value. + */ + map( + callbackfn: ( + this: This, + value: number, + index: number, + array: this, + ) => number, + thisArg?: This, + ): TypedNumberArray; + /** + * Calls the specified callback function for all the elements in an array. The return value of + * the callback function is the accumulated result, and is provided as an argument in the next + * call to the callback function. + * @param callbackfn A function that accepts up to four arguments. The reduce method calls the + * callbackfn function one time for each element in the array. + */ + reduce( + callbackfn: ( + previousValue: number | U, + currentValue: number, + currentIndex: number, + array: this, + ) => U, + ): number | U; + /** + * Calls the specified callback function for all the elements in an array. The return value of + * the callback function is the accumulated result, and is provided as an argument in the next + * call to the callback function. + * @param callbackfn A function that accepts up to four arguments. The reduce method calls the + * callbackfn function one time for each element in the array. + * @param initialValue If initialValue is specified, it is used as the initial value to start + * the accumulation. The first call to the callbackfn function provides this value as an argument + * instead of an array value. + */ + reduce( + callbackfn: ( + previousValue: U, + currentValue: number, + currentIndex: number, + array: this, + ) => U, + initialValue: U, + ): U; + /** + * Calls the specified callback function for all the elements in an array, in descending order. + * The return value of the callback function is the accumulated result, and is provided as an + * argument in the next call to the callback function. + * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls + * the callbackfn function one time for each element in the array. + */ + reduceRight( + callbackfn: ( + previousValue: number | U, + currentValue: number, + currentIndex: number, + array: this, + ) => U, + ): number | U; + /** + * Calls the specified callback function for all the elements in an array, in descending order. + * The return value of the callback function is the accumulated result, and is provided as an + * argument in the next call to the callback function. + * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls + * the callbackfn function one time for each element in the array. + * @param initialValue If initialValue is specified, it is used as the initial value to start + * the accumulation. The first call to the callbackfn function provides this value as an argument + * instead of an array value. + */ + reduceRight( + callbackfn: ( + previousValue: U, + currentValue: number, + currentIndex: number, + array: this, + ) => U, + initialValue: U, + ): U; + /** + * Determines whether the specified callback function returns true for any element of an array. + * @param predicate A function that accepts up to three arguments. The some method calls + * the predicate function for each element in the array until the predicate returns a value + * which is coercible to the Boolean value true, or until the end of the array. + * @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. + */ + some( + predicate: ( + this: This, + value: number, + index: number, + array: this, + ) => boolean, + thisArg?: This, + ): boolean; +} + +interface TypedNumberArrayConstructor { + /** + * Creates an array from an array-like or iterable object. + * @param arrayLike An array-like or iterable object to convert to an array. + */ + from(arrayLike: ArrayLike): TypedNumberArray; + /** + * Creates an array from an array-like or iterable object. + * @param arrayLike An array-like or iterable object to convert to an array. + * @param mapfn A mapping function to call on every element of the array. + * @param thisArg Value of 'this' used to invoke the mapfn. + */ + from( + arrayLike: ArrayLike, + mapfn: (this: This, v: T, k: number) => number, + thisArg?: This, + ): TypedNumberArray; +} + +interface TypedNumberArrayConstructorIter { + /** + * Creates an array from an iterable object. + * @param iterable An iterable object to convert to an array. + */ + from( + iterable: Iterable | ArrayLike, + ): TypedNumberArray; + /** + * Creates an array from an iterable object. + * @param iterable An iterable object to convert to an array. + * @param mapfn A mapping function to call on every element of the array. + * @param thisArg Value of 'this' used to invoke the mapfn. + */ + from( + iterable: Iterable | ArrayLike, + mapfn: (this: This, v: T, k: number) => number, + thisArg?: This, + ): TypedNumberArray; +} + +interface TypedBigIntArray< + TArrayBuffer extends ArrayBufferLike = ArrayBufferLike, +> { + /** + * Determines whether all the members of an array satisfy the specified test. + * @param predicate A function that accepts up to three arguments. The every method calls + * the predicate function for each element in the array until the predicate returns false, + * or until the end of the array. + * @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. + */ + every( + predicate: ( + this: This, + value: bigint, + index: number, + array: this, + ) => boolean, + thisArg?: This, + ): boolean; + /** + * Returns the elements of an array that meet the condition specified in a callback function. + * @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. + * @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. + */ + filter( + predicate: ( + this: This, + value: bigint, + index: number, + array: this, + ) => boolean, + thisArg?: This, + ): TypedBigIntArray; + /** + * Returns the value of the first element in the array where predicate is true, and undefined + * otherwise. + * @param predicate find calls predicate once for each element of the array, in ascending + * order, until it finds one where predicate returns true. If such an element is found, find + * immediately returns that element value. Otherwise, find returns undefined. + * @param thisArg If provided, it will be used as the this value for each invocation of + * predicate. If it is not provided, undefined is used instead. + */ + find( + predicate: ( + this: This, + value: bigint, + index: number, + array: this, + ) => boolean, + thisArg?: This, + ): bigint | undefined; + /** + * Returns the index of the first element in the array where predicate is true, and -1 + * otherwise. + * @param predicate find calls predicate once for each element of the array, in ascending + * order, until it finds one where predicate returns true. If such an element is found, + * findIndex immediately returns that element index. Otherwise, findIndex returns -1. + * @param thisArg If provided, it will be used as the this value for each invocation of + * predicate. If it is not provided, undefined is used instead. + */ + findIndex( + predicate: ( + this: This, + value: bigint, + index: number, + array: this, + ) => boolean, + thisArg?: This, + ): number; + /** + * Performs the specified action for each element in an array. + * @param callbackfn A function that accepts up to three arguments. forEach calls the + * callbackfn function one time for each element in the array. + * @param thisArg An object to which the this keyword can refer in the callbackfn function. + * If thisArg is omitted, undefined is used as the this value. + */ + forEach( + callbackfn: (this: This, value: bigint, index: number, array: this) => void, + thisArg?: This, + ): void; + /** + * Calls a defined callback function on each element of an array, and returns an array that + * contains the results. + * @param callbackfn A function that accepts up to three arguments. The map method calls the + * callbackfn function one time for each element in the array. + * @param thisArg An object to which the this keyword can refer in the callbackfn function. + * If thisArg is omitted, undefined is used as the this value. + */ + map( + callbackfn: ( + this: This, + value: bigint, + index: number, + array: this, + ) => bigint, + thisArg?: This, + ): TypedBigIntArray; + /** + * Calls the specified callback function for all the elements in an array. The return value of + * the callback function is the accumulated result, and is provided as an argument in the next + * call to the callback function. + * @param callbackfn A function that accepts up to four arguments. The reduce method calls the + * callbackfn function one time for each element in the array. + */ + reduce( + callbackfn: ( + previousValue: bigint | U, + currentValue: bigint, + currentIndex: number, + array: this, + ) => U, + ): bigint | U; + /** + * Calls the specified callback function for all the elements in an array. The return value of + * the callback function is the accumulated result, and is provided as an argument in the next + * call to the callback function. + * @param callbackfn A function that accepts up to four arguments. The reduce method calls the + * callbackfn function one time for each element in the array. + * @param initialValue If initialValue is specified, it is used as the initial value to start + * the accumulation. The first call to the callbackfn function provides this value as an argument + * instead of an array value. + */ + reduce( + callbackfn: ( + previousValue: U, + currentValue: bigint, + currentIndex: number, + array: this, + ) => U, + initialValue: U, + ): U; + /** + * Calls the specified callback function for all the elements in an array, in descending order. + * The return value of the callback function is the accumulated result, and is provided as an + * argument in the next call to the callback function. + * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls + * the callbackfn function one time for each element in the array. + */ + reduceRight( + callbackfn: ( + previousValue: bigint | U, + currentValue: bigint, + currentIndex: number, + array: this, + ) => U, + ): bigint | U; + /** + * Calls the specified callback function for all the elements in an array, in descending order. + * The return value of the callback function is the accumulated result, and is provided as an + * argument in the next call to the callback function. + * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls + * the callbackfn function one time for each element in the array. + * @param initialValue If initialValue is specified, it is used as the initial value to start + * the accumulation. The first call to the callbackfn function provides this value as an argument + * instead of an array value. + */ + reduceRight( + callbackfn: ( + previousValue: U, + currentValue: bigint, + currentIndex: number, + array: this, + ) => U, + initialValue: U, + ): U; + /** + * Determines whether the specified callback function returns true for any element of an array. + * @param predicate A function that accepts up to three arguments. The some method calls the + * predicate function for each element in the array until the predicate returns true, or until + * the end of the array. + * @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. + */ + some( + predicate: ( + this: This, + value: bigint, + index: number, + array: this, + ) => boolean, + thisArg?: This, + ): boolean; +} + +interface TypedBigIntArrayConstructor { + /** + * Creates an array from an array-like or iterable object. + * @param arrayLike An array-like or iterable object to convert to an array. + */ + from( + arrayLike: Iterable | ArrayLike, + ): TypedBigIntArray; + /** + * Creates an array from an array-like or iterable object. + * @param arrayLike An array-like or iterable object to convert to an array. + * @param mapfn A mapping function to call on every element of the array. + * @param thisArg Value of 'this' used to invoke the mapfn. + */ + from( + arrayLike: Iterable | ArrayLike, + mapfn: (this: This, v: T, k: number) => bigint, + thisArg?: This, + ): TypedBigIntArray; +} diff --git a/lib/lib.es2015.iterable.d.ts b/lib/lib.es2015.iterable.d.ts index 8a5f518..8646d94 100644 --- a/lib/lib.es2015.iterable.d.ts +++ b/lib/lib.es2015.iterable.d.ts @@ -63,24 +63,3 @@ interface PromiseConstructor { interface MapConstructor { new (iterable?: Iterable | null): Map; } - -interface TypedNumberArrayConstructor { - /** - * Creates an array from an iterable object. - * @param iterable An iterable object to convert to an array. - */ - from( - iterable: Iterable | ArrayLike, - ): TypedNumberArray; - /** - * Creates an array from an iterable object. - * @param iterable An iterable object to convert to an array. - * @param mapfn A mapping function to call on every element of the array. - * @param thisArg Value of 'this' used to invoke the mapfn. - */ - from( - iterable: Iterable | ArrayLike, - mapfn: (this: This, v: T, k: number) => number, - thisArg?: This, - ): TypedNumberArray; -} diff --git a/lib/lib.es2020.bigint.d.ts b/lib/lib.es2020.bigint.d.ts deleted file mode 100644 index 977bfc3..0000000 --- a/lib/lib.es2020.bigint.d.ts +++ /dev/null @@ -1,207 +0,0 @@ -interface TypedBigIntArray< - TArrayBuffer extends ArrayBufferLike = ArrayBufferLike, -> { - /** - * Determines whether all the members of an array satisfy the specified test. - * @param predicate A function that accepts up to three arguments. The every method calls - * the predicate function for each element in the array until the predicate returns false, - * or until the end of the array. - * @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. - */ - every( - predicate: ( - this: This, - value: bigint, - index: number, - array: this, - ) => boolean, - thisArg?: This, - ): boolean; - /** - * Returns the elements of an array that meet the condition specified in a callback function. - * @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. - * @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. - */ - filter( - predicate: ( - this: This, - value: bigint, - index: number, - array: this, - ) => boolean, - thisArg?: This, - ): TypedBigIntArray; - /** - * Returns the value of the first element in the array where predicate is true, and undefined - * otherwise. - * @param predicate find calls predicate once for each element of the array, in ascending - * order, until it finds one where predicate returns true. If such an element is found, find - * immediately returns that element value. Otherwise, find returns undefined. - * @param thisArg If provided, it will be used as the this value for each invocation of - * predicate. If it is not provided, undefined is used instead. - */ - find( - predicate: ( - this: This, - value: bigint, - index: number, - array: this, - ) => boolean, - thisArg?: This, - ): bigint | undefined; - /** - * Returns the index of the first element in the array where predicate is true, and -1 - * otherwise. - * @param predicate find calls predicate once for each element of the array, in ascending - * order, until it finds one where predicate returns true. If such an element is found, - * findIndex immediately returns that element index. Otherwise, findIndex returns -1. - * @param thisArg If provided, it will be used as the this value for each invocation of - * predicate. If it is not provided, undefined is used instead. - */ - findIndex( - predicate: ( - this: This, - value: bigint, - index: number, - array: this, - ) => boolean, - thisArg?: This, - ): number; - /** - * Performs the specified action for each element in an array. - * @param callbackfn A function that accepts up to three arguments. forEach calls the - * callbackfn function one time for each element in the array. - * @param thisArg An object to which the this keyword can refer in the callbackfn function. - * If thisArg is omitted, undefined is used as the this value. - */ - forEach( - callbackfn: (this: This, value: bigint, index: number, array: this) => void, - thisArg?: This, - ): void; - /** - * Calls a defined callback function on each element of an array, and returns an array that - * contains the results. - * @param callbackfn A function that accepts up to three arguments. The map method calls the - * callbackfn function one time for each element in the array. - * @param thisArg An object to which the this keyword can refer in the callbackfn function. - * If thisArg is omitted, undefined is used as the this value. - */ - map( - callbackfn: ( - this: This, - value: bigint, - index: number, - array: this, - ) => bigint, - thisArg?: This, - ): TypedBigIntArray; - /** - * Calls the specified callback function for all the elements in an array. The return value of - * the callback function is the accumulated result, and is provided as an argument in the next - * call to the callback function. - * @param callbackfn A function that accepts up to four arguments. The reduce method calls the - * callbackfn function one time for each element in the array. - */ - reduce( - callbackfn: ( - previousValue: bigint | U, - currentValue: bigint, - currentIndex: number, - array: this, - ) => U, - ): bigint | U; - /** - * Calls the specified callback function for all the elements in an array. The return value of - * the callback function is the accumulated result, and is provided as an argument in the next - * call to the callback function. - * @param callbackfn A function that accepts up to four arguments. The reduce method calls the - * callbackfn function one time for each element in the array. - * @param initialValue If initialValue is specified, it is used as the initial value to start - * the accumulation. The first call to the callbackfn function provides this value as an argument - * instead of an array value. - */ - reduce( - callbackfn: ( - previousValue: U, - currentValue: bigint, - currentIndex: number, - array: this, - ) => U, - initialValue: U, - ): U; - /** - * Calls the specified callback function for all the elements in an array, in descending order. - * The return value of the callback function is the accumulated result, and is provided as an - * argument in the next call to the callback function. - * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls - * the callbackfn function one time for each element in the array. - */ - reduceRight( - callbackfn: ( - previousValue: bigint | U, - currentValue: bigint, - currentIndex: number, - array: this, - ) => U, - ): bigint | U; - /** - * Calls the specified callback function for all the elements in an array, in descending order. - * The return value of the callback function is the accumulated result, and is provided as an - * argument in the next call to the callback function. - * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls - * the callbackfn function one time for each element in the array. - * @param initialValue If initialValue is specified, it is used as the initial value to start - * the accumulation. The first call to the callbackfn function provides this value as an argument - * instead of an array value. - */ - reduceRight( - callbackfn: ( - previousValue: U, - currentValue: bigint, - currentIndex: number, - array: this, - ) => U, - initialValue: U, - ): U; - /** - * Determines whether the specified callback function returns true for any element of an array. - * @param predicate A function that accepts up to three arguments. The some method calls the - * predicate function for each element in the array until the predicate returns true, or until - * the end of the array. - * @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. - */ - some( - predicate: ( - this: This, - value: bigint, - index: number, - array: this, - ) => boolean, - thisArg?: This, - ): boolean; -} - -interface TypedBigIntArrayConstructor { - /** - * Creates an array from an array-like or iterable object. - * @param arrayLike An array-like or iterable object to convert to an array. - */ - from( - arrayLike: Iterable | ArrayLike, - ): TypedBigIntArray; - /** - * Creates an array from an array-like or iterable object. - * @param arrayLike An array-like or iterable object to convert to an array. - * @param mapfn A mapping function to call on every element of the array. - * @param thisArg Value of 'this' used to invoke the mapfn. - */ - from( - arrayLike: Iterable | ArrayLike, - mapfn: (this: This, v: T, k: number) => bigint, - thisArg?: This, - ): TypedBigIntArray; -} diff --git a/lib/lib.es5.d.ts b/lib/lib.es5.d.ts index 21a5540..8425866 100644 --- a/lib/lib.es5.d.ts +++ b/lib/lib.es5.d.ts @@ -643,202 +643,6 @@ interface Promise extends PromiseLike { ): Promise; } -interface TypedNumberArray< - TArrayBuffer extends ArrayBufferLike = ArrayBufferLike, -> { - /** - * Determines whether all the members of an array satisfy the specified test. - * @param predicate A function that accepts up to three arguments. The every method calls - * the predicate function for each element in the array until the predicate returns a value - * which is coercible to the Boolean value false, or until the end of the array. - * @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. - */ - every( - predicate: ( - this: This, - value: number, - index: number, - array: this, - ) => boolean, - thisArg?: This, - ): boolean; - /** - * Returns the elements of an array that meet the condition specified in a callback function. - * @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. - * @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. - */ - filter( - predicate: ( - this: This, - value: number, - index: number, - array: this, - ) => boolean, - thisArg?: This, - ): TypedNumberArray; - /** - * Returns the value of the first element in the array where predicate is true, and undefined - * otherwise. - * @param predicate find calls predicate once for each element of the array, in ascending - * order, until it finds one where predicate returns true. If such an element is found, find - * immediately returns that element value. Otherwise, find returns undefined. - * @param thisArg If provided, it will be used as the this value for each invocation of - * predicate. If it is not provided, undefined is used instead. - */ - find( - predicate: (this: This, value: number, index: number, obj: this) => boolean, - thisArg?: This, - ): number | undefined; - /** - * Returns the index of the first element in the array where predicate is true, and -1 - * otherwise. - * @param predicate find calls predicate once for each element of the array, in ascending - * order, until it finds one where predicate returns true. If such an element is found, - * findIndex immediately returns that element index. Otherwise, findIndex returns -1. - * @param thisArg If provided, it will be used as the this value for each invocation of - * predicate. If it is not provided, undefined is used instead. - */ - findIndex( - predicate: (this: This, value: number, index: number, obj: this) => boolean, - thisArg?: This, - ): number; - /** - * Performs the specified action for each element in an array. - * @param callbackfn A function that accepts up to three arguments. forEach calls the - * callbackfn function one time for each element in the array. - * @param thisArg An object to which the this keyword can refer in the callbackfn function. - * If thisArg is omitted, undefined is used as the this value. - */ - forEach( - callbackfn: (this: This, value: number, index: number, array: this) => void, - thisArg?: This, - ): void; - /** - * Calls a defined callback function on each element of an array, and returns an array that - * contains the results. - * @param callbackfn A function that accepts up to three arguments. The map method calls the - * callbackfn function one time for each element in the array. - * @param thisArg An object to which the this keyword can refer in the callbackfn function. - * If thisArg is omitted, undefined is used as the this value. - */ - map( - callbackfn: ( - this: This, - value: number, - index: number, - array: this, - ) => number, - thisArg?: This, - ): TypedNumberArray; - /** - * Calls the specified callback function for all the elements in an array. The return value of - * the callback function is the accumulated result, and is provided as an argument in the next - * call to the callback function. - * @param callbackfn A function that accepts up to four arguments. The reduce method calls the - * callbackfn function one time for each element in the array. - */ - reduce( - callbackfn: ( - previousValue: number | U, - currentValue: number, - currentIndex: number, - array: this, - ) => U, - ): number | U; - /** - * Calls the specified callback function for all the elements in an array. The return value of - * the callback function is the accumulated result, and is provided as an argument in the next - * call to the callback function. - * @param callbackfn A function that accepts up to four arguments. The reduce method calls the - * callbackfn function one time for each element in the array. - * @param initialValue If initialValue is specified, it is used as the initial value to start - * the accumulation. The first call to the callbackfn function provides this value as an argument - * instead of an array value. - */ - reduce( - callbackfn: ( - previousValue: U, - currentValue: number, - currentIndex: number, - array: this, - ) => U, - initialValue: U, - ): U; - /** - * Calls the specified callback function for all the elements in an array, in descending order. - * The return value of the callback function is the accumulated result, and is provided as an - * argument in the next call to the callback function. - * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls - * the callbackfn function one time for each element in the array. - */ - reduceRight( - callbackfn: ( - previousValue: number | U, - currentValue: number, - currentIndex: number, - array: this, - ) => U, - ): number | U; - /** - * Calls the specified callback function for all the elements in an array, in descending order. - * The return value of the callback function is the accumulated result, and is provided as an - * argument in the next call to the callback function. - * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls - * the callbackfn function one time for each element in the array. - * @param initialValue If initialValue is specified, it is used as the initial value to start - * the accumulation. The first call to the callbackfn function provides this value as an argument - * instead of an array value. - */ - reduceRight( - callbackfn: ( - previousValue: U, - currentValue: number, - currentIndex: number, - array: this, - ) => U, - initialValue: U, - ): U; - /** - * Determines whether the specified callback function returns true for any element of an array. - * @param predicate A function that accepts up to three arguments. The some method calls - * the predicate function for each element in the array until the predicate returns a value - * which is coercible to the Boolean value true, or until the end of the array. - * @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. - */ - some( - predicate: ( - this: This, - value: number, - index: number, - array: this, - ) => boolean, - thisArg?: This, - ): boolean; -} - -interface TypedNumberArrayConstructor { - /** - * Creates an array from an array-like or iterable object. - * @param arrayLike An array-like or iterable object to convert to an array. - */ - from(arrayLike: ArrayLike): TypedNumberArray; - /** - * Creates an array from an array-like or iterable object. - * @param arrayLike An array-like or iterable object to convert to an array. - * @param mapfn A mapping function to call on every element of the array. - * @param thisArg Value of 'this' used to invoke the mapfn. - */ - from( - arrayLike: ArrayLike, - mapfn: (this: This, v: T, k: number) => number, - thisArg?: This, - ): TypedNumberArray; -} - /** * Construct a type with the properties of T except for those in type K. * From 047e9c02ad294480d884363f2a0078f667e0cf7e Mon Sep 17 00:00:00 2001 From: uhyo Date: Sun, 16 Mar 2025 23:07:20 +0900 Subject: [PATCH 2/2] chore: revert docs diff change --- docs/diff/es2015.iterable.d.ts.md | 80 +++----- docs/diff/es5.d.ts.md | 324 ++++++------------------------ 2 files changed, 93 insertions(+), 311 deletions(-) diff --git a/docs/diff/es2015.iterable.d.ts.md b/docs/diff/es2015.iterable.d.ts.md index 4312e49..d57b79d 100644 --- a/docs/diff/es2015.iterable.d.ts.md +++ b/docs/diff/es2015.iterable.d.ts.md @@ -6,7 +6,7 @@ Index: es2015.iterable.d.ts --- es2015.iterable.d.ts +++ es2015.iterable.d.ts @@ -20,24 +20,23 @@ - + type IteratorResult = | IteratorYieldResult | IteratorReturnResult; @@ -18,12 +18,12 @@ Index: es2015.iterable.d.ts return?(value?: TReturn): IteratorResult; throw?(e?: any): IteratorResult; } - + -interface Iterable { +interface Iterable { [Symbol.iterator](): Iterator; } - + /** * Describes a user-defined {@link Iterator} that is also iterable. */ @@ -32,7 +32,7 @@ Index: es2015.iterable.d.ts extends Iterator { [Symbol.iterator](): IterableIterator; } - + @@ -92,12 +91,12 @@ * @param iterable An iterable object to convert to an array. * @param mapfn A mapping function to call on every element of the array. @@ -47,28 +47,28 @@ Index: es2015.iterable.d.ts + thisArg?: This, ): U[]; } - + interface ReadonlyArray { @@ -121,9 +120,9 @@ } - + interface IArguments { /** Iterator */ - [Symbol.iterator](): ArrayIterator; + [Symbol.iterator](): ArrayIterator; } - + interface MapIterator extends IteratorObject { @@ -170,9 +169,8 @@ values(): MapIterator; } - + interface MapConstructor { - new (): Map; new (iterable?: Iterable | null): Map; } - + interface WeakMap {} @@ -244,17 +242,17 @@ * resolve, or rejected when any Promise is rejected. @@ -77,7 +77,7 @@ Index: es2015.iterable.d.ts */ - all(values: Iterable>): Promise[]>; + all(values: Iterable): Promise[]>; - + /** * Creates a Promise that is resolved or rejected when any of the provided Promises are resolved * or rejected. @@ -87,12 +87,12 @@ Index: es2015.iterable.d.ts - race(values: Iterable>): Promise>; + race(values: Iterable): Promise>; } - + interface StringIterator extends IteratorObject { @@ -283,26 +281,23 @@ } - + interface Int8ArrayConstructor { new (elements: Iterable): Int8Array; - @@ -124,11 +124,11 @@ Index: es2015.iterable.d.ts + thisArg?: This, ): Int8Array; } - + interface Uint8Array { @@ -322,26 +317,23 @@ } - + interface Uint8ArrayConstructor { new (elements: Iterable): Uint8Array; - @@ -160,11 +160,11 @@ Index: es2015.iterable.d.ts + thisArg?: This, ): Uint8Array; } - + interface Uint8ClampedArray { @@ -363,26 +355,25 @@ } - + interface Uint8ClampedArrayConstructor { new (elements: Iterable): Uint8ClampedArray; - @@ -198,11 +198,11 @@ Index: es2015.iterable.d.ts + thisArg?: This, ): Uint8ClampedArray; } - + interface Int16Array { @@ -404,26 +395,23 @@ } - + interface Int16ArrayConstructor { new (elements: Iterable): Int16Array; - @@ -234,11 +234,11 @@ Index: es2015.iterable.d.ts + thisArg?: This, ): Int16Array; } - + interface Uint16Array { @@ -443,26 +431,25 @@ } - + interface Uint16ArrayConstructor { new (elements: Iterable): Uint16Array; - @@ -272,11 +272,11 @@ Index: es2015.iterable.d.ts + thisArg?: This, ): Uint16Array; } - + interface Int32Array { @@ -482,26 +469,23 @@ } - + interface Int32ArrayConstructor { new (elements: Iterable): Int32Array; - @@ -308,11 +308,11 @@ Index: es2015.iterable.d.ts + thisArg?: This, ): Int32Array; } - + interface Uint32Array { @@ -521,26 +505,25 @@ } - + interface Uint32ArrayConstructor { new (elements: Iterable): Uint32Array; - @@ -346,11 +346,11 @@ Index: es2015.iterable.d.ts + thisArg?: This, ): Uint32Array; } - + interface Float32Array { @@ -560,26 +543,25 @@ } - + interface Float32ArrayConstructor { new (elements: Iterable): Float32Array; - @@ -384,11 +384,11 @@ Index: es2015.iterable.d.ts + thisArg?: This, ): Float32Array; } - + interface Float64Array { -@@ -615,23 +605,45 @@ +@@ -599,24 +581,23 @@ } - + interface Float64ArrayConstructor { new (elements: Iterable): Float64Array; - @@ -422,27 +422,5 @@ Index: es2015.iterable.d.ts + thisArg?: This, ): Float64Array; } -+// -------------------- -+ -+interface TypedNumberArrayConstructor { -+ /** -+ * Creates an array from an iterable object. -+ * @param iterable An iterable object to convert to an array. -+ */ -+ from( -+ iterable: Iterable | ArrayLike, -+ ): TypedNumberArray; -+ /** -+ * Creates an array from an iterable object. -+ * @param iterable An iterable object to convert to an array. -+ * @param mapfn A mapping function to call on every element of the array. -+ * @param thisArg Value of 'this' used to invoke the mapfn. -+ */ -+ from( -+ iterable: Iterable | ArrayLike, -+ mapfn: (this: This, v: T, k: number) => number, -+ thisArg?: This, -+ ): TypedNumberArray; -+} ``` diff --git a/docs/diff/es5.d.ts.md b/docs/diff/es5.d.ts.md index 0e6d77f..3ed6956 100644 --- a/docs/diff/es5.d.ts.md +++ b/docs/diff/es5.d.ts.md @@ -12,13 +12,13 @@ Index: es5.d.ts */ -declare function eval(x: string): any; +declare function eval(x: string): unknown; - + /** * Converts a string to an integer. * @param string A string to convert into a number. @@ -115,14 +115,27 @@ toLocaleString(): string; - + /** Returns the primitive value of the specified object. */ valueOf(): Object; - @@ -42,30 +42,30 @@ Index: es5.d.ts + [key in Key]: unknown; + } + : {}); - + /** * Determines whether an object exists in another object's prototype chain. * @param v Another object whose prototype chain is to be checked. @@ -137,75 +150,145 @@ } - + interface ObjectConstructor { new (value?: any): Object; - (): any; - (value: any): any; + (): {}; + (value: T): T extends object ? T : {}; - + /** A reference to the prototype for a class of objects. */ readonly prototype: Object; - + /** * Returns the prototype of an object. * @param o The object that references the prototype. */ - getPrototypeOf(o: any): any; + getPrototypeOf(o: {}): unknown; - + /** * Gets the own property descriptor of the specified object. * An own property descriptor is one that is defined directly on the object and is not inherited from the object's prototype. @@ -77,7 +77,7 @@ Index: es5.d.ts + o: {}, p: PropertyKey, ): PropertyDescriptor | undefined; - + /** * Returns the names of the own properties of an object. The own properties of an object are those that are defined directly * on that object, and are not inherited from the object's prototype. The properties of an object include both fields (objects) and functions. @@ -85,14 +85,14 @@ Index: es5.d.ts */ - getOwnPropertyNames(o: any): string[]; + getOwnPropertyNames(o: {}): string[]; - + /** * Creates an object that has the specified prototype or that has null prototype. * @param o Object to use as a prototype. May be null. */ - create(o: object | null): any; + create(o: O): O; - + /** + * Creates an object that has the specified prototype or that has null prototype. + * @param o Object to use as a prototype. May be null. @@ -124,7 +124,7 @@ Index: es5.d.ts + ? O[K] + : unknown; + }; - + /** + * Creates an object that has the specified prototype, and that optionally contains specified properties. + * @param o Object to use as a prototype. May be null @@ -178,7 +178,7 @@ Index: es5.d.ts + : unknown; + } + : unknown); - + /** * Adds one or more properties to an object, and/or modifies attributes of existing properties. * @param o Object on which to add or modify the properties. This can be a native JavaScript object or a DOM object. @@ -207,7 +207,7 @@ Index: es5.d.ts + ? O[K] + : unknown; + }; - + /** * Prevents the modification of attributes of existing properties, and prevents the addition of new properties. * @param o Object on which to lock the attributes. @@ -254,14 +254,14 @@ Index: es5.d.ts ...args: A ): new (...args: B) => R; } - + interface IArguments { - [index: number]: any; + [index: number]: unknown; length: number; callee: Function; } - + @@ -486,24 +567,28 @@ * Matches a string with a regular expression, and returns an array containing the results of that search. * @param regexp A variable name or string literal containing the regular expression pattern and flags. @@ -276,7 +276,7 @@ Index: es5.d.ts + * @param replaceValue A string containing the text to replace for every successful match of searchValue in this string. */ replace(searchValue: string | RegExp, replaceValue: string): string; - + /** * Replaces text in a string, using a regular expression or search string. - * @param searchValue A string to search for. @@ -293,7 +293,7 @@ Index: es5.d.ts + ...rest: (string | number)[] + ) => string, ): string; - + /** * Finds the first substring match in a regular expression search. @@ -1200,37 +1285,71 @@ @@ -378,7 +378,7 @@ Index: es5.d.ts + space?: string | number | null | undefined, + ): string | undefined; } - + /** * An intrinsic object that provides functions to convert JavaScript values to and from the JavaScript Object Notation (JSON) format. @@ -1294,23 +1413,25 @@ @@ -566,7 +566,7 @@ Index: es5.d.ts ) => U, initialValue: U, ): U; - + @@ -1552,23 +1658,25 @@ * which is coercible to the Boolean value false, or until the end of the array. * @param thisArg An object to which the this keyword can refer in the predicate function. @@ -752,10 +752,10 @@ Index: es5.d.ts ) => U, initialValue: U, ): U; - + [n: number]: T; } - + interface ArrayConstructor { - new (arrayLength?: number): any[]; new (arrayLength: number): T[]; @@ -768,12 +768,12 @@ Index: es5.d.ts + isArray(arg: any): arg is unknown[]; + readonly prototype: unknown[]; } - + declare var Array: ArrayConstructor; - + @@ -1716,9 +1807,11 @@ } - + declare type PromiseConstructorLike = new ( executor: ( - resolve: (value: T | PromiseLike) => void, @@ -783,7 +783,7 @@ Index: es5.d.ts reject: (reason?: any) => void, ) => void, ) => PromiseLike; - + @@ -1728,52 +1821,56 @@ * @param onfulfilled The callback to execute when the Promise is resolved. * @param onrejected The callback to execute when the Promise is rejected. @@ -815,7 +815,7 @@ Index: es5.d.ts + onrejected?: ((reason: unknown) => U | PromiseLike) | null | undefined, + ): PromiseLike; } - + -/** - * Represents the completion of an asynchronous operation - */ @@ -841,7 +841,7 @@ Index: es5.d.ts + onfulfilled: (value: T) => U | PromiseLike, + onrejected?: ((reason: unknown) => U | PromiseLike) | null | undefined, + ): Promise; - + /** + * Attaches callbacks for the resolution and/or rejection of the Promise. + * @param onfulfilled The callback to execute when the Promise is resolved. @@ -868,12 +868,12 @@ Index: es5.d.ts + onrejected: ((reason: unknown) => U | PromiseLike) | null | undefined, + ): Promise; } - + /** * Recursively unwraps the "awaited type" of a type. Non-promise "thenables" should resolve to `never`. This emulates the behavior of `await`. @@ -1837,8 +1934,11 @@ type Extract = T extends U ? T : never; - + /** * Construct a type with the properties of T except for those in type K. + * @@ -881,7 +881,7 @@ Index: es5.d.ts + * @see {@link https://github.com/microsoft/TypeScript/issues/54451} */ type Omit = Pick>; - + /** @@ -2138,20 +2238,24 @@ * is treated as length+end. @@ -909,7 +909,7 @@ Index: es5.d.ts + ) => boolean, + thisArg?: This, ): boolean; - + /** * Changes all array elements from `start` to `end` index to a static `value` and returns the modified array @@ -2161,21 +2265,24 @@ @@ -987,7 +987,7 @@ Index: es5.d.ts + callbackfn: (this: This, value: number, index: number, array: this) => void, + thisArg?: This, ): void; - + /** * Returns the index of the first occurrence of a value in an array. @@ -2241,50 +2346,40 @@ @@ -1143,7 +1143,7 @@ Index: es5.d.ts + ) => boolean, + thisArg?: This, ): boolean; - + /** * Sorts an array. @@ -2438,25 +2523,23 @@ @@ -1174,7 +1174,7 @@ Index: es5.d.ts ): Int8Array; } declare var Int8Array: Int8ArrayConstructor; - + @@ -2494,20 +2577,24 @@ * is treated as length+end. * @param end If not specified, length of the this object is used as its default value. @@ -1201,7 +1201,7 @@ Index: es5.d.ts + ) => boolean, + thisArg?: This, ): boolean; - + /** * Changes all array elements from `start` to `end` index to a static `value` and returns the modified array @@ -2517,21 +2604,24 @@ @@ -1279,7 +1279,7 @@ Index: es5.d.ts + callbackfn: (this: This, value: number, index: number, array: this) => void, + thisArg?: This, ): void; - + /** * Returns the index of the first occurrence of a value in an array. @@ -2597,50 +2685,40 @@ @@ -1435,7 +1435,7 @@ Index: es5.d.ts + ) => boolean, + thisArg?: This, ): boolean; - + /** * Sorts an array. @@ -2794,25 +2862,23 @@ @@ -1466,7 +1466,7 @@ Index: es5.d.ts ): Uint8Array; } declare var Uint8Array: Uint8ArrayConstructor; - + @@ -2852,20 +2918,24 @@ * is treated as length+end. * @param end If not specified, length of the this object is used as its default value. @@ -1493,7 +1493,7 @@ Index: es5.d.ts + ) => boolean, + thisArg?: This, ): boolean; - + /** * Changes all array elements from `start` to `end` index to a static `value` and returns the modified array @@ -2875,21 +2945,24 @@ @@ -1571,7 +1571,7 @@ Index: es5.d.ts + callbackfn: (this: This, value: number, index: number, array: this) => void, + thisArg?: This, ): void; - + /** * Returns the index of the first occurrence of a value in an array. @@ -2955,50 +3026,40 @@ @@ -1727,7 +1727,7 @@ Index: es5.d.ts + ) => boolean, + thisArg?: This, ): boolean; - + /** * Sorts an array. @@ -3152,25 +3203,23 @@ @@ -1758,7 +1758,7 @@ Index: es5.d.ts ): Uint8ClampedArray; } declare var Uint8ClampedArray: Uint8ClampedArrayConstructor; - + @@ -3208,20 +3257,24 @@ * is treated as length+end. * @param end If not specified, length of the this object is used as its default value. @@ -1785,7 +1785,7 @@ Index: es5.d.ts + ) => boolean, + thisArg?: This, ): boolean; - + /** * Changes all array elements from `start` to `end` index to a static `value` and returns the modified array @@ -3231,21 +3284,24 @@ @@ -2019,7 +2019,7 @@ Index: es5.d.ts + ) => boolean, + thisArg?: This, ): boolean; - + /** * Sorts an array. @@ -3507,25 +3541,23 @@ @@ -2050,7 +2050,7 @@ Index: es5.d.ts ): Int16Array; } declare var Int16Array: Int16ArrayConstructor; - + @@ -3563,20 +3595,24 @@ * is treated as length+end. * @param end If not specified, length of the this object is used as its default value. @@ -2077,7 +2077,7 @@ Index: es5.d.ts + ) => boolean, + thisArg?: This, ): boolean; - + /** * Changes all array elements from `start` to `end` index to a static `value` and returns the modified array @@ -3586,21 +3622,24 @@ @@ -2155,7 +2155,7 @@ Index: es5.d.ts + callbackfn: (this: This, value: number, index: number, array: this) => void, + thisArg?: This, ): void; - + /** * Returns the index of the first occurrence of a value in an array. @@ -3666,50 +3703,40 @@ @@ -2311,7 +2311,7 @@ Index: es5.d.ts + ) => boolean, + thisArg?: This, ): boolean; - + /** * Sorts an array. @@ -3863,25 +3880,23 @@ @@ -2369,7 +2369,7 @@ Index: es5.d.ts + ) => boolean, + thisArg?: This, ): boolean; - + /** * Changes all array elements from `start` to `end` index to a static `value` and returns the modified array @@ -3941,21 +3960,24 @@ @@ -2447,7 +2447,7 @@ Index: es5.d.ts + callbackfn: (this: This, value: number, index: number, array: this) => void, + thisArg?: This, ): void; - + /** * Returns the index of the first occurrence of a value in an array. @@ -4021,50 +4041,40 @@ @@ -2603,7 +2603,7 @@ Index: es5.d.ts + ) => boolean, + thisArg?: This, ): boolean; - + /** * Sorts an array. @@ -4218,25 +4218,23 @@ @@ -2634,7 +2634,7 @@ Index: es5.d.ts ): Int32Array; } declare var Int32Array: Int32ArrayConstructor; - + @@ -4274,20 +4272,24 @@ * is treated as length+end. * @param end If not specified, length of the this object is used as its default value. @@ -2661,7 +2661,7 @@ Index: es5.d.ts + ) => boolean, + thisArg?: This, ): boolean; - + /** * Changes all array elements from `start` to `end` index to a static `value` and returns the modified array @@ -4297,21 +4299,24 @@ @@ -2895,7 +2895,7 @@ Index: es5.d.ts + ) => boolean, + thisArg?: This, ): boolean; - + /** * Sorts an array. @@ -4573,25 +4556,23 @@ @@ -2926,7 +2926,7 @@ Index: es5.d.ts ): Uint32Array; } declare var Uint32Array: Uint32ArrayConstructor; - + @@ -4629,20 +4610,24 @@ * is treated as length+end. * @param end If not specified, length of the this object is used as its default value. @@ -2953,7 +2953,7 @@ Index: es5.d.ts + ) => boolean, + thisArg?: This, ): boolean; - + /** * Changes all array elements from `start` to `end` index to a static `value` and returns the modified array @@ -4652,21 +4637,24 @@ @@ -3031,7 +3031,7 @@ Index: es5.d.ts + callbackfn: (this: This, value: number, index: number, array: this) => void, + thisArg?: This, ): void; - + /** * Returns the index of the first occurrence of a value in an array. @@ -4732,50 +4718,40 @@ @@ -3187,7 +3187,7 @@ Index: es5.d.ts + ) => boolean, + thisArg?: This, ): boolean; - + /** * Sorts an array. @@ -4929,25 +4895,23 @@ @@ -3218,7 +3218,7 @@ Index: es5.d.ts ): Float32Array; } declare var Float32Array: Float32ArrayConstructor; - + @@ -4985,20 +4949,24 @@ * is treated as length+end. * @param end If not specified, length of the this object is used as its default value. @@ -3245,7 +3245,7 @@ Index: es5.d.ts + ) => boolean, + thisArg?: This, ): boolean; - + /** * Changes all array elements from `start` to `end` index to a static `value` and returns the modified array @@ -5008,21 +4976,24 @@ @@ -3323,7 +3323,7 @@ Index: es5.d.ts + callbackfn: (this: This, value: number, index: number, array: this) => void, + thisArg?: This, ): void; - + /** * Returns the index of the first occurrence of a value in an array. @@ -5088,50 +5057,40 @@ @@ -3479,7 +3479,7 @@ Index: es5.d.ts + ) => boolean, + thisArg?: This, ): boolean; - + /** * Sorts an array. @@ -5285,25 +5234,23 @@ @@ -3510,8 +3510,8 @@ Index: es5.d.ts ): Float64Array; } declare var Float64Array: Float64ArrayConstructor; - -@@ -5609,4 +5556,229 @@ + +@@ -5564,4 +5511,33 @@ locales?: string | string[], options?: Intl.DateTimeFormatOptions, ): string; @@ -3545,201 +3545,5 @@ Index: es5.d.ts +type UndefinedDomain = symbol | SomeFunction | SomeConstructor | undefined; +type StringifyResultT = A extends UndefinedDomain ? undefined : string; +type StringifyResult = StringifyResultT | SomeExtends; -+ -+interface TypedNumberArray< -+ TArrayBuffer extends ArrayBufferLike = ArrayBufferLike, -+> { -+ /** -+ * Determines whether all the members of an array satisfy the specified test. -+ * @param predicate A function that accepts up to three arguments. The every method calls -+ * the predicate function for each element in the array until the predicate returns a value -+ * which is coercible to the Boolean value false, or until the end of the array. -+ * @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. -+ */ -+ every( -+ predicate: ( -+ this: This, -+ value: number, -+ index: number, -+ array: this, -+ ) => boolean, -+ thisArg?: This, -+ ): boolean; -+ /** -+ * Returns the elements of an array that meet the condition specified in a callback function. -+ * @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. -+ * @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. -+ */ -+ filter( -+ predicate: ( -+ this: This, -+ value: number, -+ index: number, -+ array: this, -+ ) => boolean, -+ thisArg?: This, -+ ): TypedNumberArray; -+ /** -+ * Returns the value of the first element in the array where predicate is true, and undefined -+ * otherwise. -+ * @param predicate find calls predicate once for each element of the array, in ascending -+ * order, until it finds one where predicate returns true. If such an element is found, find -+ * immediately returns that element value. Otherwise, find returns undefined. -+ * @param thisArg If provided, it will be used as the this value for each invocation of -+ * predicate. If it is not provided, undefined is used instead. -+ */ -+ find( -+ predicate: (this: This, value: number, index: number, obj: this) => boolean, -+ thisArg?: This, -+ ): number | undefined; -+ /** -+ * Returns the index of the first element in the array where predicate is true, and -1 -+ * otherwise. -+ * @param predicate find calls predicate once for each element of the array, in ascending -+ * order, until it finds one where predicate returns true. If such an element is found, -+ * findIndex immediately returns that element index. Otherwise, findIndex returns -1. -+ * @param thisArg If provided, it will be used as the this value for each invocation of -+ * predicate. If it is not provided, undefined is used instead. -+ */ -+ findIndex( -+ predicate: (this: This, value: number, index: number, obj: this) => boolean, -+ thisArg?: This, -+ ): number; -+ /** -+ * Performs the specified action for each element in an array. -+ * @param callbackfn A function that accepts up to three arguments. forEach calls the -+ * callbackfn function one time for each element in the array. -+ * @param thisArg An object to which the this keyword can refer in the callbackfn function. -+ * If thisArg is omitted, undefined is used as the this value. -+ */ -+ forEach( -+ callbackfn: (this: This, value: number, index: number, array: this) => void, -+ thisArg?: This, -+ ): void; -+ /** -+ * Calls a defined callback function on each element of an array, and returns an array that -+ * contains the results. -+ * @param callbackfn A function that accepts up to three arguments. The map method calls the -+ * callbackfn function one time for each element in the array. -+ * @param thisArg An object to which the this keyword can refer in the callbackfn function. -+ * If thisArg is omitted, undefined is used as the this value. -+ */ -+ map( -+ callbackfn: ( -+ this: This, -+ value: number, -+ index: number, -+ array: this, -+ ) => number, -+ thisArg?: This, -+ ): TypedNumberArray; -+ /** -+ * Calls the specified callback function for all the elements in an array. The return value of -+ * the callback function is the accumulated result, and is provided as an argument in the next -+ * call to the callback function. -+ * @param callbackfn A function that accepts up to four arguments. The reduce method calls the -+ * callbackfn function one time for each element in the array. -+ */ -+ reduce( -+ callbackfn: ( -+ previousValue: number | U, -+ currentValue: number, -+ currentIndex: number, -+ array: this, -+ ) => U, -+ ): number | U; -+ /** -+ * Calls the specified callback function for all the elements in an array. The return value of -+ * the callback function is the accumulated result, and is provided as an argument in the next -+ * call to the callback function. -+ * @param callbackfn A function that accepts up to four arguments. The reduce method calls the -+ * callbackfn function one time for each element in the array. -+ * @param initialValue If initialValue is specified, it is used as the initial value to start -+ * the accumulation. The first call to the callbackfn function provides this value as an argument -+ * instead of an array value. -+ */ -+ reduce( -+ callbackfn: ( -+ previousValue: U, -+ currentValue: number, -+ currentIndex: number, -+ array: this, -+ ) => U, -+ initialValue: U, -+ ): U; -+ /** -+ * Calls the specified callback function for all the elements in an array, in descending order. -+ * The return value of the callback function is the accumulated result, and is provided as an -+ * argument in the next call to the callback function. -+ * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls -+ * the callbackfn function one time for each element in the array. -+ */ -+ reduceRight( -+ callbackfn: ( -+ previousValue: number | U, -+ currentValue: number, -+ currentIndex: number, -+ array: this, -+ ) => U, -+ ): number | U; -+ /** -+ * Calls the specified callback function for all the elements in an array, in descending order. -+ * The return value of the callback function is the accumulated result, and is provided as an -+ * argument in the next call to the callback function. -+ * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls -+ * the callbackfn function one time for each element in the array. -+ * @param initialValue If initialValue is specified, it is used as the initial value to start -+ * the accumulation. The first call to the callbackfn function provides this value as an argument -+ * instead of an array value. -+ */ -+ reduceRight( -+ callbackfn: ( -+ previousValue: U, -+ currentValue: number, -+ currentIndex: number, -+ array: this, -+ ) => U, -+ initialValue: U, -+ ): U; -+ /** -+ * Determines whether the specified callback function returns true for any element of an array. -+ * @param predicate A function that accepts up to three arguments. The some method calls -+ * the predicate function for each element in the array until the predicate returns a value -+ * which is coercible to the Boolean value true, or until the end of the array. -+ * @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. -+ */ -+ some( -+ predicate: ( -+ this: This, -+ value: number, -+ index: number, -+ array: this, -+ ) => boolean, -+ thisArg?: This, -+ ): boolean; -+} -+ -+interface TypedNumberArrayConstructor { -+ /** -+ * Creates an array from an array-like or iterable object. -+ * @param arrayLike An array-like or iterable object to convert to an array. -+ */ -+ from(arrayLike: ArrayLike): TypedNumberArray; -+ /** -+ * Creates an array from an array-like or iterable object. -+ * @param arrayLike An array-like or iterable object to convert to an array. -+ * @param mapfn A mapping function to call on every element of the array. -+ * @param thisArg Value of 'this' used to invoke the mapfn. -+ */ -+ from( -+ arrayLike: ArrayLike, -+ mapfn: (this: This, v: T, k: number) => number, -+ thisArg?: This, -+ ): TypedNumberArray; -+} ```