Skip to content

Commit b59d905

Browse files
committed
Map WebIDL object to TypeScript object
This type on the TS side is relatively new, which is probably why it wasn't used in the first place, but gives more precise definitions and, so, better type checking. As a side-effect, fixes microsoft#290 (although in a different way).
1 parent 353a0cf commit b59d905

File tree

4 files changed

+44
-45
lines changed

4 files changed

+44
-45
lines changed

baselines/dom.generated.d.ts

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ interface AudioWorkletNodeOptions extends AudioNodeOptions {
130130
numberOfOutputs?: number;
131131
outputChannelCount?: number[];
132132
parameterData?: Record<string, number>;
133-
processorOptions?: any;
133+
processorOptions?: object | null;
134134
}
135135

136136
interface AuthenticationExtensionsClientInputs {
@@ -948,7 +948,7 @@ interface PaymentDetailsInit extends PaymentDetailsBase {
948948

949949
interface PaymentDetailsModifier {
950950
additionalDisplayItems?: PaymentItem[];
951-
data?: any;
951+
data?: object;
952952
supportedMethods: string | string[];
953953
total?: PaymentItem;
954954
}
@@ -965,7 +965,7 @@ interface PaymentItem {
965965
}
966966

967967
interface PaymentMethodData {
968-
data?: any;
968+
data?: object;
969969
supportedMethods: string | string[];
970970
}
971971

@@ -1043,7 +1043,7 @@ interface PositionOptions {
10431043
}
10441044

10451045
interface PostMessageOptions {
1046-
transfer?: any[];
1046+
transfer?: object[];
10471047
}
10481048

10491049
interface ProgressEventInit extends EventInit {
@@ -2465,14 +2465,14 @@ interface BhxBrowser {
24652465
clearLastError(): void;
24662466
currentWindowId(): number;
24672467
fireExtensionApiTelemetry(functionName: string, isSucceeded: boolean, isSupported: boolean, errorString: string): void;
2468-
genericFunction(functionId: number, destination: any, parameters?: string, callbackId?: number): void;
2468+
genericFunction(functionId: number, destination: object, parameters?: string, callbackId?: number): void;
24692469
genericSynchronousFunction(functionId: number, parameters?: string): string;
24702470
getExtensionId(): string;
2471-
getThisAddress(): any;
2471+
getThisAddress(): object;
24722472
registerGenericFunctionCallbackHandler(callbackHandler: Function): void;
24732473
registerGenericListenerHandler(eventHandler: Function): void;
24742474
setLastError(parameters: string): void;
2475-
webPlatformGenericFunction(destination: any, parameters?: string, callbackId?: number): void;
2475+
webPlatformGenericFunction(destination: object, parameters?: string, callbackId?: number): void;
24762476
}
24772477

24782478
declare var BhxBrowser: {
@@ -3636,7 +3636,7 @@ interface ConcatParams extends Algorithm {
36363636

36373637
/** Provides access to the browser's debugging console (e.g. the Web Console in Firefox). The specifics of how it works varies from browser to browser, but there is a de facto set of features that are typically provided. */
36383638
interface Console {
3639-
memory: any;
3639+
memory: object;
36403640
assert(condition?: boolean, message?: string, ...data: any[]): void;
36413641
clear(): void;
36423642
count(label?: string): void;
@@ -3978,7 +3978,7 @@ interface DOMMatrixReadOnly {
39783978
skewY(sy?: number): DOMMatrix;
39793979
toFloat32Array(): Float32Array;
39803980
toFloat64Array(): Float64Array;
3981-
toJSON(): any;
3981+
toJSON(): object;
39823982
transformPoint(point?: DOMPointInit): DOMPoint;
39833983
translate(tx?: number, ty?: number, tz?: number): DOMMatrix;
39843984
}
@@ -4023,7 +4023,7 @@ interface DOMPointReadOnly {
40234023
readonly y: number;
40244024
readonly z: number;
40254025
matrixTransform(matrix?: DOMMatrixInit): DOMPoint;
4026-
toJSON(): any;
4026+
toJSON(): object;
40274027
}
40284028

40294029
declare var DOMPointReadOnly: {
@@ -4038,7 +4038,7 @@ interface DOMQuad {
40384038
readonly p3: DOMPoint;
40394039
readonly p4: DOMPoint;
40404040
getBounds(): DOMRect;
4041-
toJSON(): any;
4041+
toJSON(): object;
40424042
}
40434043

40444044
declare var DOMQuad: {
@@ -4084,7 +4084,7 @@ interface DOMRectReadOnly {
40844084
readonly width: number;
40854085
readonly x: number;
40864086
readonly y: number;
4087-
toJSON(): any;
4087+
toJSON(): object;
40884088
}
40894089

40904090
declare var DOMRectReadOnly: {
@@ -5483,13 +5483,13 @@ declare var EventTarget: {
54835483
interface ExtensionScriptApis {
54845484
extensionIdToShortId(extensionId: string): number;
54855485
fireExtensionApiTelemetry(functionName: string, isSucceeded: boolean, isSupported: boolean, errorString: string): void;
5486-
genericFunction(routerAddress: any, parameters?: string, callbackId?: number): void;
5486+
genericFunction(routerAddress: object, parameters?: string, callbackId?: number): void;
54875487
genericSynchronousFunction(functionId: number, parameters?: string): string;
5488-
genericWebRuntimeCallout(to: any, from: any, payload: string): void;
5488+
genericWebRuntimeCallout(to: object, from: object, payload: string): void;
54895489
getExtensionId(): string;
54905490
registerGenericFunctionCallbackHandler(callbackHandler: Function): void;
54915491
registerGenericPersistentCallbackHandler(callbackHandler: Function): void;
5492-
registerWebRuntimeCallbackHandler(handler: Function): any;
5492+
registerWebRuntimeCallbackHandler(handler: Function): object;
54935493
}
54945494

54955495
declare var ExtensionScriptApis: {
@@ -10185,7 +10185,7 @@ interface MediaDeviceInfo {
1018510185
readonly groupId: string;
1018610186
readonly kind: MediaDeviceKind;
1018710187
readonly label: string;
10188-
toJSON(): any;
10188+
toJSON(): object;
1018910189
}
1019010190

1019110191
declare var MediaDeviceInfo: {
@@ -11559,7 +11559,7 @@ declare var PaymentRequestUpdateEvent: {
1155911559

1156011560
/** This Payment Request API interface is returned after a user selects a payment method and approves a payment request. */
1156111561
interface PaymentResponse {
11562-
readonly details: any;
11562+
readonly details: object;
1156311563
readonly methodName: string;
1156411564
readonly payerEmail: string | null;
1156511565
readonly payerName: string | null;
@@ -11627,7 +11627,7 @@ interface Performance extends EventTarget {
1162711627
measure(measureName: string, startMark?: string, endMark?: string): void;
1162811628
now(): number;
1162911629
setResourceTimingBufferSize(maxSize: number): void;
11630-
toJSON(): any;
11630+
toJSON(): object;
1163111631
addEventListener<K extends keyof PerformanceEventMap>(type: K, listener: (this: Performance, ev: PerformanceEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
1163211632
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
1163311633
removeEventListener<K extends keyof PerformanceEventMap>(type: K, listener: (this: Performance, ev: PerformanceEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
@@ -11645,7 +11645,7 @@ interface PerformanceEntry {
1164511645
readonly entryType: string;
1164611646
readonly name: string;
1164711647
readonly startTime: number;
11648-
toJSON(): any;
11648+
toJSON(): object;
1164911649
}
1165011650

1165111651
declare var PerformanceEntry: {
@@ -11675,7 +11675,7 @@ declare var PerformanceMeasure: {
1167511675
interface PerformanceNavigation {
1167611676
readonly redirectCount: number;
1167711677
readonly type: number;
11678-
toJSON(): any;
11678+
toJSON(): object;
1167911679
readonly TYPE_BACK_FORWARD: number;
1168011680
readonly TYPE_NAVIGATE: number;
1168111681
readonly TYPE_RELOAD: number;
@@ -11703,7 +11703,7 @@ interface PerformanceNavigationTiming extends PerformanceResourceTiming {
1170311703
readonly type: NavigationType;
1170411704
readonly unloadEventEnd: number;
1170511705
readonly unloadEventStart: number;
11706-
toJSON(): any;
11706+
toJSON(): object;
1170711707
}
1170811708

1170911709
declare var PerformanceNavigationTiming: {
@@ -11753,7 +11753,7 @@ interface PerformanceResourceTiming extends PerformanceEntry {
1175311753
readonly secureConnectionStart: number;
1175411754
readonly transferSize: number;
1175511755
readonly workerStart: number;
11756-
toJSON(): any;
11756+
toJSON(): object;
1175711757
}
1175811758

1175911759
declare var PerformanceResourceTiming: {
@@ -11784,7 +11784,7 @@ interface PerformanceTiming {
1178411784
readonly secureConnectionStart: number;
1178511785
readonly unloadEventEnd: number;
1178611786
readonly unloadEventStart: number;
11787-
toJSON(): any;
11787+
toJSON(): object;
1178811788
}
1178911789

1179011790
declare var PerformanceTiming: {
@@ -12476,7 +12476,7 @@ declare var RTCSctpTransport: {
1247612476
interface RTCSessionDescription {
1247712477
readonly sdp: string;
1247812478
readonly type: RTCSdpType;
12479-
toJSON(): any;
12479+
toJSON(): object;
1248012480
}
1248112481

1248212482
declare var RTCSessionDescription: {
@@ -12532,7 +12532,7 @@ declare var RTCStatsProvider: {
1253212532
};
1253312533

1253412534
interface RTCStatsReport {
12535-
forEach(callbackfn: (value: any, key: string, parent: RTCStatsReport) => void, thisArg?: any): void;
12535+
forEach(callbackfn: (value: object, key: string, parent: RTCStatsReport) => void, thisArg?: any): void;
1253612536
}
1253712537

1253812538
declare var RTCStatsReport: {
@@ -19043,12 +19043,12 @@ declare namespace WebAssembly {
1904319043
};
1904419044

1904519045
interface Instance {
19046-
readonly exports: any;
19046+
readonly exports: object;
1904719047
}
1904819048

1904919049
var Instance: {
1905019050
prototype: Instance;
19051-
new(module: Module, importObject?: any): Instance;
19051+
new(module: Module, importObject?: object): Instance;
1905219052
};
1905319053

1905419054
interface LinkError {
@@ -19135,8 +19135,8 @@ declare namespace WebAssembly {
1913519135
type ImportExportKind = "function" | "table" | "memory" | "global";
1913619136
type TableKind = "anyfunc";
1913719137
function compile(bytes: BufferSource): Promise<Module>;
19138-
function instantiate(bytes: BufferSource, importObject?: any): Promise<WebAssemblyInstantiatedSource>;
19139-
function instantiate(moduleObject: Module, importObject?: any): Promise<Instance>;
19138+
function instantiate(bytes: BufferSource, importObject?: object): Promise<WebAssemblyInstantiatedSource>;
19139+
function instantiate(moduleObject: Module, importObject?: object): Promise<Instance>;
1914019140
function validate(bytes: BufferSource): boolean;
1914119141
}
1914219142

baselines/dom.iterable.generated.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ interface RTCRtpTransceiver {
189189
setCodecPreferences(codecs: Iterable<RTCRtpCodecCapability>): void;
190190
}
191191

192-
interface RTCStatsReport extends ReadonlyMap<string, any> {
192+
interface RTCStatsReport extends ReadonlyMap<string, object> {
193193
}
194194

195195
interface SVGLengthList {

baselines/webworker.generated.d.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ interface PipeOptions {
327327
}
328328

329329
interface PostMessageOptions {
330-
transfer?: any[];
330+
transfer?: object[];
331331
}
332332

333333
interface ProgressEventInit extends EventInit {
@@ -906,7 +906,7 @@ interface ConcatParams extends Algorithm {
906906

907907
/** Provides access to the browser's debugging console (e.g. the Web Console in Firefox). The specifics of how it works varies from browser to browser, but there is a de facto set of features that are typically provided. */
908908
interface Console {
909-
memory: any;
909+
memory: object;
910910
assert(condition?: boolean, message?: string, ...data: any[]): void;
911911
clear(): void;
912912
count(label?: string): void;
@@ -1132,7 +1132,7 @@ interface DOMMatrixReadOnly {
11321132
skewY(sy?: number): DOMMatrix;
11331133
toFloat32Array(): Float32Array;
11341134
toFloat64Array(): Float64Array;
1135-
toJSON(): any;
1135+
toJSON(): object;
11361136
transformPoint(point?: DOMPointInit): DOMPoint;
11371137
translate(tx?: number, ty?: number, tz?: number): DOMMatrix;
11381138
}
@@ -1164,7 +1164,7 @@ interface DOMPointReadOnly {
11641164
readonly y: number;
11651165
readonly z: number;
11661166
matrixTransform(matrix?: DOMMatrixInit): DOMPoint;
1167-
toJSON(): any;
1167+
toJSON(): object;
11681168
}
11691169

11701170
declare var DOMPointReadOnly: {
@@ -1179,7 +1179,7 @@ interface DOMQuad {
11791179
readonly p3: DOMPoint;
11801180
readonly p4: DOMPoint;
11811181
getBounds(): DOMRect;
1182-
toJSON(): any;
1182+
toJSON(): object;
11831183
}
11841184

11851185
declare var DOMQuad: {
@@ -1211,7 +1211,7 @@ interface DOMRectReadOnly {
12111211
readonly width: number;
12121212
readonly x: number;
12131213
readonly y: number;
1214-
toJSON(): any;
1214+
toJSON(): object;
12151215
}
12161216

12171217
declare var DOMRectReadOnly: {
@@ -2493,7 +2493,7 @@ interface Performance extends EventTarget {
24932493
measure(measureName: string, startMark?: string, endMark?: string): void;
24942494
now(): number;
24952495
setResourceTimingBufferSize(maxSize: number): void;
2496-
toJSON(): any;
2496+
toJSON(): object;
24972497
addEventListener<K extends keyof PerformanceEventMap>(type: K, listener: (this: Performance, ev: PerformanceEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
24982498
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
24992499
removeEventListener<K extends keyof PerformanceEventMap>(type: K, listener: (this: Performance, ev: PerformanceEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
@@ -2511,7 +2511,7 @@ interface PerformanceEntry {
25112511
readonly entryType: string;
25122512
readonly name: string;
25132513
readonly startTime: number;
2514-
toJSON(): any;
2514+
toJSON(): object;
25152515
}
25162516

25172517
declare var PerformanceEntry: {
@@ -2579,7 +2579,7 @@ interface PerformanceResourceTiming extends PerformanceEntry {
25792579
readonly secureConnectionStart: number;
25802580
readonly transferSize: number;
25812581
readonly workerStart: number;
2582-
toJSON(): any;
2582+
toJSON(): object;
25832583
}
25842584

25852585
declare var PerformanceResourceTiming: {
@@ -5604,12 +5604,12 @@ declare namespace WebAssembly {
56045604
};
56055605

56065606
interface Instance {
5607-
readonly exports: any;
5607+
readonly exports: object;
56085608
}
56095609

56105610
var Instance: {
56115611
prototype: Instance;
5612-
new(module: Module, importObject?: any): Instance;
5612+
new(module: Module, importObject?: object): Instance;
56135613
};
56145614

56155615
interface Memory {
@@ -5680,8 +5680,8 @@ declare namespace WebAssembly {
56805680
type ImportExportKind = "function" | "table" | "memory" | "global";
56815681
type TableKind = "anyfunc";
56825682
function compile(bytes: BufferSource): Promise<Module>;
5683-
function instantiate(bytes: BufferSource, importObject?: any): Promise<WebAssemblyInstantiatedSource>;
5684-
function instantiate(moduleObject: Module, importObject?: any): Promise<Instance>;
5683+
function instantiate(bytes: BufferSource, importObject?: object): Promise<WebAssemblyInstantiatedSource>;
5684+
function instantiate(moduleObject: Module, importObject?: object): Promise<Instance>;
56855685
function validate(bytes: BufferSource): boolean;
56865686
}
56875687

src/helpers.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@ export const bufferSourceTypes = new Set(["ArrayBuffer", "ArrayBufferView", "Dat
55
export const integerTypes = new Set(["byte", "octet", "short", "unsigned short", "long", "unsigned long", "long long", "unsigned long long"]);
66
export const stringTypes = new Set(["ByteString", "DOMString", "USVString", "CSSOMString"]);
77
const floatTypes = new Set(["float", "unrestricted float", "double", "unrestricted double"]);
8-
const sameTypes = new Set(["any", "boolean", "Date", "Function", "Promise", "void"]);
8+
const sameTypes = new Set(["any", "boolean", "object", "Date", "Function", "Promise", "void"]);
99
export const baseTypeConversionMap = new Map<string, string>([
1010
...[...bufferSourceTypes].map(type => [type, type] as [string, string]),
1111
...[...integerTypes].map(type => [type, "number"] as [string, string]),
1212
...[...floatTypes].map(type => [type, "number"] as [string, string]),
1313
...[...stringTypes].map(type => [type, "string"] as [string, string]),
1414
...[...sameTypes].map(type => [type, type] as [string, string]),
15-
["object", "any"],
1615
["sequence", "Array"],
1716
["record", "Record"],
1817
["FrozenArray", "ReadonlyArray"],

0 commit comments

Comments
 (0)