From 5380de725c655108fb634ffb0a55cfa8559802ed Mon Sep 17 00:00:00 2001 From: ExE Boss <3889017+ExE-Boss@users.noreply.github.com> Date: Fri, 31 Dec 2021 00:47:04 +0100 Subject: [PATCH] =?UTF-8?q?typings:=20add=C2=A0types=20for=C2=A0symbol=20a?= =?UTF-8?q?nd=C2=A0accessor=C2=A0properties=20on=C2=A0`primordials`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/40992 Reviewed-By: James M Snell --- typings/primordials.d.ts | 169 +++++++++++++++++++++++++++------------ 1 file changed, 117 insertions(+), 52 deletions(-) diff --git a/typings/primordials.d.ts b/typings/primordials.d.ts index 5c291769de66b1..72d5a36701f651 100644 --- a/typings/primordials.d.ts +++ b/typings/primordials.d.ts @@ -1,5 +1,3 @@ -import { AsyncIterator } from "internal/webstreams/util"; - type UncurryThis unknown> = (self: ThisParameterType, ...args: Parameters) => ReturnType; type UncurryThisStaticApply unknown> = @@ -7,6 +5,22 @@ type UncurryThisStaticApply unk type StaticApply unknown> = (args: Parameters) => ReturnType; +type UncurryMethod = + O[K] extends (this: infer U, ...args: infer A) => infer R + ? (self: unknown extends U ? T : U, ...args: A) => R + : never; +type UncurryMethodApply = + O[K] extends (this: infer U, ...args: infer A) => infer R + ? (self: unknown extends U ? T : U, args: A) => R + : never; + +type UncurryGetter = + O[K] extends infer V ? (self: T) => V : never; +type UncurrySetter = + O[K] extends infer V ? (self: T, value: V) => void : never; + +type TypedArrayContentType = T extends { [k: number]: infer V } ? V : never; + /** * Primordials are a way to safely use globals without fear of global mutation * Generally, this means removing `this` parameter usage and instead using @@ -24,17 +38,14 @@ type StaticApply unknown> = * primordials.StringPrototypeStartsWith('thing', 'hello') * ``` */ -declare namespace Primordials { - export function uncurryThis< - T extends (...args: unknown[]) => unknown - > (fn: T): - (self: ThisType, ...args: Parameters) => ReturnType; +declare namespace primordials { + export function uncurryThis unknown>(fn: T): UncurryThis; export function makeSafe(unsafe: NewableFunction, safe: T): T; - export const decodeURI: typeof globalThis.decodeURI; - export const decodeURIComponent: typeof globalThis.decodeURIComponent; - export const encodeURI: typeof globalThis.encodeURI; - export const encodeURIComponent: typeof globalThis.encodeURIComponent; + export import decodeURI = globalThis.decodeURI; + export import decodeURIComponent = globalThis.decodeURIComponent; + export import encodeURI = globalThis.encodeURI; + export import encodeURIComponent = globalThis.encodeURIComponent; export const JSONParse: typeof JSON.parse export const JSONStringify: typeof JSON.stringify export const MathAbs: typeof Math.abs @@ -94,11 +105,11 @@ declare namespace Primordials { export const ReflectPreventExtensions: typeof Reflect.preventExtensions export const ReflectSet: typeof Reflect.set export const ReflectSetPrototypeOf: typeof Reflect.setPrototypeOf - export const AggregateError: typeof globalThis.AggregateError; + export import AggregateError = globalThis.AggregateError; export const AggregateErrorLength: typeof AggregateError.length export const AggregateErrorName: typeof AggregateError.name export const AggregateErrorPrototype: typeof AggregateError.prototype - export const Array: typeof globalThis.Array; + export import Array = globalThis.Array; export const ArrayLength: typeof Array.length export const ArrayName: typeof Array.name export const ArrayPrototype: typeof Array.prototype @@ -138,14 +149,15 @@ declare namespace Primordials { export const ArrayPrototypeReduceRight: UncurryThis export const ArrayPrototypeToLocaleString: UncurryThis export const ArrayPrototypeToString: UncurryThis - export const ArrayBuffer: typeof globalThis.ArrayBuffer; + export const ArrayPrototypeSymbolIterator: UncurryMethod; + export import ArrayBuffer = globalThis.ArrayBuffer; export const ArrayBufferLength: typeof ArrayBuffer.length export const ArrayBufferName: typeof ArrayBuffer.name export const ArrayBufferPrototype: typeof ArrayBuffer.prototype export const ArrayBufferIsView: typeof ArrayBuffer.isView export const ArrayBufferPrototypeSlice: UncurryThis - export const AsyncIteratorPrototype: UncurryThis - export const BigInt: typeof globalThis.BigInt; + export const AsyncIteratorPrototype: AsyncIterable; + export import BigInt = globalThis.BigInt; export const BigIntLength: typeof BigInt.length export const BigIntName: typeof BigInt.name export const BigIntPrototype: typeof BigInt.prototype @@ -154,23 +166,23 @@ declare namespace Primordials { export const BigIntPrototypeToLocaleString: UncurryThis export const BigIntPrototypeToString: UncurryThis export const BigIntPrototypeValueOf: UncurryThis - export const BigInt64Array: typeof globalThis.BigInt64Array; + export import BigInt64Array = globalThis.BigInt64Array; export const BigInt64ArrayLength: typeof BigInt64Array.length export const BigInt64ArrayName: typeof BigInt64Array.name export const BigInt64ArrayPrototype: typeof BigInt64Array.prototype export const BigInt64ArrayBYTES_PER_ELEMENT: typeof BigInt64Array.BYTES_PER_ELEMENT - export const BigUint64Array: typeof globalThis.BigUint64Array; + export import BigUint64Array = globalThis.BigUint64Array; export const BigUint64ArrayLength: typeof BigUint64Array.length export const BigUint64ArrayName: typeof BigUint64Array.name export const BigUint64ArrayPrototype: typeof BigUint64Array.prototype export const BigUint64ArrayBYTES_PER_ELEMENT: typeof BigUint64Array.BYTES_PER_ELEMENT - export const Boolean: typeof globalThis.Boolean; + export import Boolean = globalThis.Boolean; export const BooleanLength: typeof Boolean.length export const BooleanName: typeof Boolean.name export const BooleanPrototype: typeof Boolean.prototype export const BooleanPrototypeToString: UncurryThis export const BooleanPrototypeValueOf: UncurryThis - export const DataView: typeof globalThis.DataView; + export import DataView = globalThis.DataView; export const DataViewLength: typeof DataView.length export const DataViewName: typeof DataView.name export const DataViewPrototype: typeof DataView.prototype @@ -194,7 +206,10 @@ declare namespace Primordials { export const DataViewPrototypeSetBigInt64: UncurryThis export const DataViewPrototypeGetBigUint64: UncurryThis export const DataViewPrototypeSetBigUint64: UncurryThis - export const Date: typeof globalThis.Date; + export const DataViewPrototypeGetBuffer: UncurryGetter; + export const DataViewPrototypeGetByteLength: UncurryGetter; + export const DataViewPrototypeGetByteOffset: UncurryGetter; + export import Date = globalThis.Date; export const DateLength: typeof Date.length export const DateName: typeof Date.name export const DatePrototype: typeof Date.prototype @@ -247,28 +262,29 @@ declare namespace Primordials { export const DatePrototypeToLocaleString: UncurryThis export const DatePrototypeToLocaleDateString: UncurryThis export const DatePrototypeToLocaleTimeString: UncurryThis - export const Error: typeof globalThis.Error; + export const DatePrototypeSymbolToPrimitive: UncurryMethod; + export import Error = globalThis.Error; export const ErrorLength: typeof Error.length export const ErrorName: typeof Error.name export const ErrorPrototype: typeof Error.prototype export const ErrorCaptureStackTrace: typeof Error.captureStackTrace export const ErrorStackTraceLimit: typeof Error.stackTraceLimit export const ErrorPrototypeToString: UncurryThis - export const EvalError: typeof globalThis.EvalError; + export import EvalError = globalThis.EvalError; export const EvalErrorLength: typeof EvalError.length export const EvalErrorName: typeof EvalError.name export const EvalErrorPrototype: typeof EvalError.prototype - export const Float32Array: typeof globalThis.Float32Array; + export import Float32Array = globalThis.Float32Array; export const Float32ArrayLength: typeof Float32Array.length export const Float32ArrayName: typeof Float32Array.name export const Float32ArrayPrototype: typeof Float32Array.prototype export const Float32ArrayBYTES_PER_ELEMENT: typeof Float32Array.BYTES_PER_ELEMENT - export const Float64Array: typeof globalThis.Float64Array; + export import Float64Array = globalThis.Float64Array; export const Float64ArrayLength: typeof Float64Array.length export const Float64ArrayName: typeof Float64Array.name export const Float64ArrayPrototype: typeof Float64Array.prototype export const Float64ArrayBYTES_PER_ELEMENT: typeof Float64Array.BYTES_PER_ELEMENT - export const Function: typeof globalThis.Function; + export import Function = globalThis.Function; export const FunctionLength: typeof Function.length export const FunctionName: typeof Function.name export const FunctionPrototype: typeof Function.prototype @@ -276,22 +292,22 @@ declare namespace Primordials { export const FunctionPrototypeBind: UncurryThis export const FunctionPrototypeCall: UncurryThis export const FunctionPrototypeToString: UncurryThis - export const Int16Array: typeof globalThis.Int16Array; + export import Int16Array = globalThis.Int16Array; export const Int16ArrayLength: typeof Int16Array.length export const Int16ArrayName: typeof Int16Array.name export const Int16ArrayPrototype: typeof Int16Array.prototype export const Int16ArrayBYTES_PER_ELEMENT: typeof Int16Array.BYTES_PER_ELEMENT - export const Int32Array: typeof globalThis.Int32Array; + export import Int32Array = globalThis.Int32Array; export const Int32ArrayLength: typeof Int32Array.length export const Int32ArrayName: typeof Int32Array.name export const Int32ArrayPrototype: typeof Int32Array.prototype export const Int32ArrayBYTES_PER_ELEMENT: typeof Int32Array.BYTES_PER_ELEMENT - export const Int8Array: typeof globalThis.Int8Array; + export import Int8Array = globalThis.Int8Array; export const Int8ArrayLength: typeof Int8Array.length export const Int8ArrayName: typeof Int8Array.name export const Int8ArrayPrototype: typeof Int8Array.prototype export const Int8ArrayBYTES_PER_ELEMENT: typeof Int8Array.BYTES_PER_ELEMENT - export const Map: typeof globalThis.Map; + export import Map = globalThis.Map; export const MapLength: typeof Map.length export const MapName: typeof Map.name export const MapPrototype: typeof Map.prototype @@ -304,7 +320,8 @@ declare namespace Primordials { export const MapPrototypeForEach: UncurryThis export const MapPrototypeKeys: UncurryThis export const MapPrototypeValues: UncurryThis - export const Number: typeof globalThis.Number; + export const MapPrototypeGetSize: UncurryGetter; + export import Number = globalThis.Number; export const NumberLength: typeof Number.length export const NumberName: typeof Number.name export const NumberPrototype: typeof Number.prototype @@ -328,7 +345,7 @@ declare namespace Primordials { export const NumberPrototypeToString: UncurryThis export const NumberPrototypeValueOf: UncurryThis export const NumberPrototypeToLocaleString: UncurryThis - export const Object: typeof globalThis.Object; + export import Object = globalThis.Object; export const ObjectLength: typeof Object.length export const ObjectName: typeof Object.name export const ObjectPrototype: typeof Object.prototype @@ -363,15 +380,15 @@ declare namespace Primordials { export const ObjectPrototypeToString: UncurryThis export const ObjectPrototypeValueOf: UncurryThis export const ObjectPrototypeToLocaleString: UncurryThis - export const RangeError: typeof globalThis.RangeError; + export import RangeError = globalThis.RangeError; export const RangeErrorLength: typeof RangeError.length export const RangeErrorName: typeof RangeError.name export const RangeErrorPrototype: typeof RangeError.prototype - export const ReferenceError: typeof globalThis.ReferenceError; + export import ReferenceError = globalThis.ReferenceError; export const ReferenceErrorLength: typeof ReferenceError.length export const ReferenceErrorName: typeof ReferenceError.name export const ReferenceErrorPrototype: typeof ReferenceError.prototype - export const RegExp: typeof globalThis.RegExp; + export import RegExp = globalThis.RegExp; export const RegExpLength: typeof RegExp.length export const RegExpName: typeof RegExp.name export const RegExpPrototype: typeof RegExp.prototype @@ -379,7 +396,15 @@ declare namespace Primordials { export const RegExpPrototypeCompile: UncurryThis export const RegExpPrototypeToString: UncurryThis export const RegExpPrototypeTest: UncurryThis - export const Set: typeof globalThis.Set; + export const RegExpPrototypeGetDotAll: UncurryGetter; + export const RegExpPrototypeGetFlags: UncurryGetter; + export const RegExpPrototypeGetGlobal: UncurryGetter; + export const RegExpPrototypeGetIgnoreCase: UncurryGetter; + export const RegExpPrototypeGetMultiline: UncurryGetter; + export const RegExpPrototypeGetSource: UncurryGetter; + export const RegExpPrototypeGetSticky: UncurryGetter; + export const RegExpPrototypeGetUnicode: UncurryGetter; + export import Set = globalThis.Set; export const SetLength: typeof Set.length export const SetName: typeof Set.name export const SetPrototype: typeof Set.prototype @@ -391,7 +416,8 @@ declare namespace Primordials { export const SetPrototypeForEach: UncurryThis export const SetPrototypeValues: UncurryThis export const SetPrototypeKeys: UncurryThis - export const String: typeof globalThis.String; + export const SetPrototypeGetSize: UncurryGetter; + export import String = globalThis.String; export const StringLength: typeof String.length export const StringName: typeof String.name export const StringPrototype: typeof String.prototype @@ -445,7 +471,7 @@ declare namespace Primordials { export const StringPrototypeToUpperCase: UncurryThis export const StringPrototypeValueOf: UncurryThis export const StringPrototypeReplaceAll: UncurryThis - export const Symbol: typeof globalThis.Symbol; + export import Symbol = globalThis.Symbol; export const SymbolLength: typeof Symbol.length export const SymbolName: typeof Symbol.name export const SymbolPrototype: typeof Symbol.prototype @@ -466,39 +492,82 @@ declare namespace Primordials { export const SymbolUnscopables: typeof Symbol.unscopables export const SymbolPrototypeToString: UncurryThis export const SymbolPrototypeValueOf: UncurryThis - export const SyntaxError: typeof globalThis.SyntaxError; + export const SymbolPrototypeSymbolToPrimitive: UncurryMethod; + export const SymbolPrototypeGetDescription: UncurryGetter; + export import SyntaxError = globalThis.SyntaxError; export const SyntaxErrorLength: typeof SyntaxError.length export const SyntaxErrorName: typeof SyntaxError.name export const SyntaxErrorPrototype: typeof SyntaxError.prototype - export const TypeError: typeof globalThis.TypeError; + export import TypeError = globalThis.TypeError; export const TypeErrorLength: typeof TypeError.length export const TypeErrorName: typeof TypeError.name export const TypeErrorPrototype: typeof TypeError.prototype - export const URIError: typeof globalThis.URIError; + export function TypedArrayFrom( + constructor: new (length: number) => T, + source: + | Iterable> + | ArrayLike>, + ): T; + export function TypedArrayFrom( + constructor: new (length: number) => T, + source: Iterable | ArrayLike, + mapfn: ( + this: THIS_ARG, + value: U, + index: number, + ) => TypedArrayContentType, + thisArg?: THIS_ARG, + ): T; + export function TypedArrayOf( + constructor: new (length: number) => T, + ...items: readonly TypedArrayContentType[] + ): T; + export function TypedArrayOfApply( + constructor: new (length: number) => T, + items: readonly TypedArrayContentType[], + ): T; + export const TypedArrayPrototypeGetBuffer: UncurryGetter; + export const TypedArrayPrototypeGetByteLength: UncurryGetter; + export const TypedArrayPrototypeGetByteOffset: UncurryGetter; + export const TypedArrayPrototypeGetLength: UncurryGetter; + export function TypedArrayPrototypeGetSymbolToStringTag(self: unknown): + | 'Int8Array' + | 'Int16Array' + | 'Int32Array' + | 'Uint8Array' + | 'Uint16Array' + | 'Uint32Array' + | 'Uint8ClampedArray' + | 'BigInt64Array' + | 'BigUint64Array' + | 'Float32Array' + | 'Float64Array' + | undefined; + export import URIError = globalThis.URIError; export const URIErrorLength: typeof URIError.length export const URIErrorName: typeof URIError.name export const URIErrorPrototype: typeof URIError.prototype - export const Uint16Array: typeof globalThis.Uint16Array; + export import Uint16Array = globalThis.Uint16Array; export const Uint16ArrayLength: typeof Uint16Array.length export const Uint16ArrayName: typeof Uint16Array.name export const Uint16ArrayPrototype: typeof Uint16Array.prototype export const Uint16ArrayBYTES_PER_ELEMENT: typeof Uint16Array.BYTES_PER_ELEMENT - export const Uint32Array: typeof globalThis.Uint32Array; + export import Uint32Array = globalThis.Uint32Array; export const Uint32ArrayLength: typeof Uint32Array.length export const Uint32ArrayName: typeof Uint32Array.name export const Uint32ArrayPrototype: typeof Uint32Array.prototype export const Uint32ArrayBYTES_PER_ELEMENT: typeof Uint32Array.BYTES_PER_ELEMENT - export const Uint8Array: typeof globalThis.Uint8Array; + export import Uint8Array = globalThis.Uint8Array; export const Uint8ArrayLength: typeof Uint8Array.length export const Uint8ArrayName: typeof Uint8Array.name export const Uint8ArrayPrototype: typeof Uint8Array.prototype export const Uint8ArrayBYTES_PER_ELEMENT: typeof Uint8Array.BYTES_PER_ELEMENT - export const Uint8ClampedArray: typeof globalThis.Uint8ClampedArray; + export import Uint8ClampedArray = globalThis.Uint8ClampedArray; export const Uint8ClampedArrayLength: typeof Uint8ClampedArray.length export const Uint8ClampedArrayName: typeof Uint8ClampedArray.name export const Uint8ClampedArrayPrototype: typeof Uint8ClampedArray.prototype export const Uint8ClampedArrayBYTES_PER_ELEMENT: typeof Uint8ClampedArray.BYTES_PER_ELEMENT - export const WeakMap: typeof globalThis.WeakMap; + export import WeakMap = globalThis.WeakMap; export const WeakMapLength: typeof WeakMap.length export const WeakMapName: typeof WeakMap.name export const WeakMapPrototype: typeof WeakMap.prototype @@ -506,14 +575,14 @@ declare namespace Primordials { export const WeakMapPrototypeGet: UncurryThis export const WeakMapPrototypeSet: UncurryThis export const WeakMapPrototypeHas: UncurryThis - export const WeakSet: typeof globalThis.WeakSet; + export import WeakSet = globalThis.WeakSet; export const WeakSetLength: typeof WeakSet.length export const WeakSetName: typeof WeakSet.name export const WeakSetPrototype: typeof WeakSet.prototype export const WeakSetPrototypeDelete: UncurryThis export const WeakSetPrototypeHas: UncurryThis export const WeakSetPrototypeAdd: UncurryThis - export const Promise: typeof globalThis.Promise; + export import Promise = globalThis.Promise; export const PromiseLength: typeof Promise.length export const PromiseName: typeof Promise.name export const PromisePrototype: typeof Promise.prototype @@ -527,7 +596,3 @@ declare namespace Primordials { export const PromisePrototypeCatch: UncurryThis export const PromisePrototypeFinally: UncurryThis } - -declare global { - const primordials: typeof Primordials; -}