Skip to content

Commit 5a752e5

Browse files
authored
Adding in typescript_type to the js_sys types (#2028)
1 parent db8d3e4 commit 5a752e5

File tree

1 file changed

+41
-39
lines changed

1 file changed

+41
-39
lines changed

crates/js-sys/src/lib.rs

+41-39
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ extern "C" {
127127
// Array
128128
#[wasm_bindgen]
129129
extern "C" {
130-
#[wasm_bindgen(extends = Object, is_type_of = Array::is_array)]
130+
#[wasm_bindgen(extends = Object, is_type_of = Array::is_array, typescript_type = "Array<any>")]
131131
#[derive(Clone, Debug, PartialEq, Eq)]
132132
pub type Array;
133133

@@ -503,7 +503,7 @@ where
503503
// ArrayBuffer
504504
#[wasm_bindgen]
505505
extern "C" {
506-
#[wasm_bindgen(extends = Object)]
506+
#[wasm_bindgen(extends = Object, typescript_type = "ArrayBuffer")]
507507
#[derive(Clone, Debug, PartialEq, Eq)]
508508
pub type ArrayBuffer;
509509

@@ -553,7 +553,7 @@ extern "C" {
553553
// SharedArrayBuffer
554554
#[wasm_bindgen]
555555
extern "C" {
556-
#[wasm_bindgen(extends = Object)]
556+
#[wasm_bindgen(extends = Object, typescript_type = "SharedArrayBuffer")]
557557
#[derive(Clone, Debug)]
558558
pub type SharedArrayBuffer;
559559

@@ -769,7 +769,7 @@ pub mod Atomics {
769769
// Boolean
770770
#[wasm_bindgen]
771771
extern "C" {
772-
#[wasm_bindgen(extends = Object, is_type_of = |v| v.as_bool().is_some())]
772+
#[wasm_bindgen(extends = Object, is_type_of = |v| v.as_bool().is_some(), typescript_type = "boolean")]
773773
#[derive(Clone, PartialEq, Eq)]
774774
pub type Boolean;
775775

@@ -817,7 +817,7 @@ impl fmt::Debug for Boolean {
817817
// DataView
818818
#[wasm_bindgen]
819819
extern "C" {
820-
#[wasm_bindgen(extends = Object)]
820+
#[wasm_bindgen(extends = Object, typescript_type = "DataView")]
821821
#[derive(Clone, Debug, PartialEq, Eq)]
822822
pub type DataView;
823823

@@ -1049,7 +1049,7 @@ extern "C" {
10491049
// Error
10501050
#[wasm_bindgen]
10511051
extern "C" {
1052-
#[wasm_bindgen(extends = Object)]
1052+
#[wasm_bindgen(extends = Object, typescript_type = "Error")]
10531053
#[derive(Clone, Debug, PartialEq, Eq)]
10541054
pub type Error;
10551055

@@ -1088,7 +1088,7 @@ extern "C" {
10881088
// EvalError
10891089
#[wasm_bindgen]
10901090
extern "C" {
1091-
#[wasm_bindgen(extends = Object, extends = Error)]
1091+
#[wasm_bindgen(extends = Object, extends = Error, typescript_type = "EvalError")]
10921092
#[derive(Clone, Debug, PartialEq, Eq)]
10931093
pub type EvalError;
10941094

@@ -1104,7 +1104,7 @@ extern "C" {
11041104
// Function
11051105
#[wasm_bindgen]
11061106
extern "C" {
1107-
#[wasm_bindgen(extends = Object, is_type_of = JsValue::is_function)]
1107+
#[wasm_bindgen(extends = Object, is_type_of = JsValue::is_function, typescript_type = "Function")]
11081108
#[derive(Clone, Debug, PartialEq, Eq)]
11091109
pub type Function;
11101110

@@ -1253,7 +1253,7 @@ impl Function {
12531253
// Generator
12541254
#[wasm_bindgen]
12551255
extern "C" {
1256-
#[wasm_bindgen(extends = Object)]
1256+
#[wasm_bindgen(extends = Object, typescript_type = "Generator<any, any, any>")]
12571257
#[derive(Clone, Debug, PartialEq, Eq)]
12581258
pub type Generator;
12591259

@@ -1281,7 +1281,7 @@ extern "C" {
12811281
// Map
12821282
#[wasm_bindgen]
12831283
extern "C" {
1284-
#[wasm_bindgen(extends = Object)]
1284+
#[wasm_bindgen(extends = Object, typescript_type = "Map<any, any>")]
12851285
#[derive(Clone, Debug, PartialEq, Eq)]
12861286
pub type Map;
12871287

@@ -1374,7 +1374,7 @@ extern "C" {
13741374
///
13751375
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols)
13761376
#[derive(Clone, Debug)]
1377-
#[wasm_bindgen(is_type_of = Iterator::looks_like_iterator)]
1377+
#[wasm_bindgen(is_type_of = Iterator::looks_like_iterator, typescript_type = "Iterator<any>")]
13781378
pub type Iterator;
13791379

13801380
/// The `next()` method always has to return an object with appropriate
@@ -1413,7 +1413,7 @@ extern "C" {
14131413
///
14141414
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of)
14151415
#[derive(Clone, Debug)]
1416-
#[wasm_bindgen(is_type_of = Iterator::looks_like_iterator)]
1416+
#[wasm_bindgen(is_type_of = Iterator::looks_like_iterator, typescript_type = "Iterator<Promise<any>>")]
14171417
pub type AsyncIterator;
14181418

14191419
/// The `next()` method always has to return a Promise which resolves to an object
@@ -1534,7 +1534,7 @@ extern "C" {
15341534
/// The result of calling `next()` on a JS iterator.
15351535
///
15361536
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols)
1537-
#[wasm_bindgen(extends = Object)]
1537+
#[wasm_bindgen(extends = Object, typescript_type = "IteratorResult<any>")]
15381538
#[derive(Clone, Debug, PartialEq, Eq)]
15391539
pub type IteratorNext;
15401540

@@ -1806,7 +1806,7 @@ pub mod Math {
18061806
// Number.
18071807
#[wasm_bindgen]
18081808
extern "C" {
1809-
#[wasm_bindgen(extends = Object, is_type_of = |v| v.as_f64().is_some())]
1809+
#[wasm_bindgen(extends = Object, is_type_of = |v| v.as_f64().is_some(), typescript_type = "number")]
18101810
#[derive(Clone)]
18111811
pub type Number;
18121812

@@ -1974,7 +1974,7 @@ impl fmt::Debug for Number {
19741974
// Date.
19751975
#[wasm_bindgen]
19761976
extern "C" {
1977-
#[wasm_bindgen(extends = Object)]
1977+
#[wasm_bindgen(extends = Object, typescript_type = "Date")]
19781978
#[derive(Clone, Debug, PartialEq, Eq)]
19791979
pub type Date;
19801980

@@ -2416,6 +2416,7 @@ extern "C" {
24162416
// Object.
24172417
#[wasm_bindgen]
24182418
extern "C" {
2419+
#[wasm_bindgen(typescript_type = "object")]
24192420
#[derive(Clone, Debug)]
24202421
pub type Object;
24212422

@@ -2683,6 +2684,7 @@ impl Eq for Object {}
26832684
// Proxy
26842685
#[wasm_bindgen]
26852686
extern "C" {
2687+
#[wasm_bindgen(typescript_type = "ProxyConstructor")]
26862688
#[derive(Clone, Debug)]
26872689
pub type Proxy;
26882690

@@ -2709,7 +2711,7 @@ extern "C" {
27092711
/// or range of allowed values.
27102712
///
27112713
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError)
2712-
#[wasm_bindgen(extends = Error, extends = Object)]
2714+
#[wasm_bindgen(extends = Error, extends = Object, typescript_type = "RangeError")]
27132715
#[derive(Clone, Debug, PartialEq, Eq)]
27142716
pub type RangeError;
27152717

@@ -2728,7 +2730,7 @@ extern "C" {
27282730
/// variable is referenced.
27292731
///
27302732
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError)
2731-
#[wasm_bindgen(extends = Error, extends = Object)]
2733+
#[wasm_bindgen(extends = Error, extends = Object, typescript_type = "ReferenceError")]
27322734
#[derive(Clone, Debug, PartialEq, Eq)]
27332735
pub type ReferenceError;
27342736

@@ -2919,7 +2921,7 @@ pub mod Reflect {
29192921
// RegExp
29202922
#[wasm_bindgen]
29212923
extern "C" {
2922-
#[wasm_bindgen(extends = Object)]
2924+
#[wasm_bindgen(extends = Object, typescript_type = "RegExp")]
29232925
#[derive(Clone, Debug, PartialEq, Eq)]
29242926
pub type RegExp;
29252927

@@ -3096,7 +3098,7 @@ extern "C" {
30963098
// Set
30973099
#[wasm_bindgen]
30983100
extern "C" {
3099-
#[wasm_bindgen(extends = Object)]
3101+
#[wasm_bindgen(extends = Object, typescript_type = "Set<any>")]
31003102
#[derive(Clone, Debug, PartialEq, Eq)]
31013103
pub type Set;
31023104

@@ -3186,7 +3188,7 @@ extern "C" {
31863188
/// parsing code.
31873189
///
31883190
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError)
3189-
#[wasm_bindgen(extends = Error, extends = Object)]
3191+
#[wasm_bindgen(extends = Error, extends = Object, typescript_type = "SyntaxError")]
31903192
#[derive(Clone, Debug, PartialEq, Eq)]
31913193
pub type SyntaxError;
31923194

@@ -3206,7 +3208,7 @@ extern "C" {
32063208
/// expected type.
32073209
///
32083210
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError)
3209-
#[wasm_bindgen(extends = Error, extends = Object)]
3211+
#[wasm_bindgen(extends = Error, extends = Object, typescript_type = "TypeError")]
32103212
#[derive(Clone, Debug, PartialEq, Eq)]
32113213
pub type TypeError;
32123214

@@ -3225,7 +3227,7 @@ extern "C" {
32253227
/// function was used in a wrong way.
32263228
///
32273229
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError)
3228-
#[wasm_bindgen(extends = Error, extends = Object, js_name = URIError)]
3230+
#[wasm_bindgen(extends = Error, extends = Object, js_name = URIError, typescript_type = "URIError")]
32293231
#[derive(Clone, Debug, PartialEq, Eq)]
32303232
pub type UriError;
32313233

@@ -3240,7 +3242,7 @@ extern "C" {
32403242
// WeakMap
32413243
#[wasm_bindgen]
32423244
extern "C" {
3243-
#[wasm_bindgen(extends = Object)]
3245+
#[wasm_bindgen(extends = Object, typescript_type = "WeakMap<object, any>")]
32443246
#[derive(Clone, Debug, PartialEq, Eq)]
32453247
pub type WeakMap;
32463248

@@ -3284,7 +3286,7 @@ extern "C" {
32843286
// WeakSet
32853287
#[wasm_bindgen]
32863288
extern "C" {
3287-
#[wasm_bindgen(extends = Object)]
3289+
#[wasm_bindgen(extends = Object, typescript_type = "WeakSet<object>")]
32883290
#[derive(Clone, Debug, PartialEq, Eq)]
32893291
pub type WeakSet;
32903292

@@ -3371,7 +3373,7 @@ pub mod WebAssembly {
33713373
/// WebAssembly decoding or validation.
33723374
///
33733375
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/CompileError)
3374-
#[wasm_bindgen(extends = Error, js_namespace = WebAssembly)]
3376+
#[wasm_bindgen(extends = Error, js_namespace = WebAssembly, typescript_type = "WebAssembly.CompileError")]
33753377
#[derive(Clone, Debug, PartialEq, Eq)]
33763378
pub type CompileError;
33773379

@@ -3393,7 +3395,7 @@ pub mod WebAssembly {
33933395
/// JavaScript.
33943396
///
33953397
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance)
3396-
#[wasm_bindgen(extends = Object, js_namespace = WebAssembly)]
3398+
#[wasm_bindgen(extends = Object, js_namespace = WebAssembly, typescript_type = "WebAssembly.Instance")]
33973399
#[derive(Clone, Debug, PartialEq, Eq)]
33983400
pub type Instance;
33993401

@@ -3424,7 +3426,7 @@ pub mod WebAssembly {
34243426
/// instantiation (besides traps from the start function).
34253427
///
34263428
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/LinkError)
3427-
#[wasm_bindgen(extends = Error, js_namespace = WebAssembly)]
3429+
#[wasm_bindgen(extends = Error, js_namespace = WebAssembly, typescript_type = "WebAssembly.LinkError")]
34283430
#[derive(Clone, Debug, PartialEq, Eq)]
34293431
pub type LinkError;
34303432

@@ -3445,7 +3447,7 @@ pub mod WebAssembly {
34453447
/// specifies a trap.
34463448
///
34473449
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/RuntimeError)
3448-
#[wasm_bindgen(extends = Error, js_namespace = WebAssembly)]
3450+
#[wasm_bindgen(extends = Error, js_namespace = WebAssembly, typescript_type = "WebAssembly.RuntimeError")]
34493451
#[derive(Clone, Debug, PartialEq, Eq)]
34503452
pub type RuntimeError;
34513453

@@ -3466,7 +3468,7 @@ pub mod WebAssembly {
34663468
/// efficiently shared with Workers, and instantiated multiple times.
34673469
///
34683470
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module)
3469-
#[wasm_bindgen(js_namespace = WebAssembly, extends = Object)]
3471+
#[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Module")]
34703472
#[derive(Clone, Debug, PartialEq, Eq)]
34713473
pub type Module;
34723474

@@ -3508,7 +3510,7 @@ pub mod WebAssembly {
35083510
/// of the given size and element type.
35093511
///
35103512
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table)
3511-
#[wasm_bindgen(js_namespace = WebAssembly, extends = Object)]
3513+
#[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Table")]
35123514
#[derive(Clone, Debug, PartialEq, Eq)]
35133515
pub type Table;
35143516

@@ -3554,7 +3556,7 @@ pub mod WebAssembly {
35543556
#[wasm_bindgen]
35553557
extern "C" {
35563558
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory)
3557-
#[wasm_bindgen(js_namespace = WebAssembly, extends = Object)]
3559+
#[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Memory")]
35583560
#[derive(Clone, Debug, PartialEq, Eq)]
35593561
pub type Memory;
35603562

@@ -3659,7 +3661,7 @@ pub mod JSON {
36593661
// JsString
36603662
#[wasm_bindgen]
36613663
extern "C" {
3662-
#[wasm_bindgen(js_name = String, extends = Object, is_type_of = JsValue::is_string)]
3664+
#[wasm_bindgen(js_name = String, extends = Object, is_type_of = JsValue::is_string, typescript_type = "string")]
36633665
#[derive(Clone, PartialEq, Eq)]
36643666
pub type JsString;
36653667

@@ -4261,7 +4263,7 @@ impl fmt::Debug for JsString {
42614263
// Symbol
42624264
#[wasm_bindgen]
42634265
extern "C" {
4264-
#[wasm_bindgen(is_type_of = JsValue::is_symbol)]
4266+
#[wasm_bindgen(is_type_of = JsValue::is_symbol, typescript_type = "Symbol")]
42654267
#[derive(Clone, Debug)]
42664268
pub type Symbol;
42674269

@@ -4417,7 +4419,7 @@ pub mod Intl {
44174419
/// that enable language sensitive string comparison.
44184420
///
44194421
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator)
4420-
#[wasm_bindgen(extends = Object, js_namespace = Intl)]
4422+
#[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.Collator")]
44214423
#[derive(Clone, Debug)]
44224424
pub type Collator;
44234425

@@ -4461,7 +4463,7 @@ pub mod Intl {
44614463
/// that enable language-sensitive date and time formatting.
44624464
///
44634465
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat)
4464-
#[wasm_bindgen(extends = Object, js_namespace = Intl)]
4466+
#[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.DateTimeFormat")]
44654467
#[derive(Clone, Debug)]
44664468
pub type DateTimeFormat;
44674469

@@ -4512,7 +4514,7 @@ pub mod Intl {
45124514
/// that enable language sensitive number formatting.
45134515
///
45144516
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat)
4515-
#[wasm_bindgen(extends = Object, js_namespace = Intl)]
4517+
#[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.NumberFormat")]
45164518
#[derive(Clone, Debug)]
45174519
pub type NumberFormat;
45184520

@@ -4562,7 +4564,7 @@ pub mod Intl {
45624564
/// that enable plural sensitive formatting and plural language rules.
45634565
///
45644566
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules)
4565-
#[wasm_bindgen(extends = Object, js_namespace = Intl)]
4567+
#[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.PluralRules")]
45664568
#[derive(Clone, Debug)]
45674569
pub type PluralRules;
45684570

@@ -4606,7 +4608,7 @@ extern "C" {
46064608
///
46074609
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
46084610
#[must_use]
4609-
#[wasm_bindgen(extends = Object)]
4611+
#[wasm_bindgen(extends = Object, typescript_type = "Promise<any>")]
46104612
#[derive(Clone, Debug)]
46114613
pub type Promise;
46124614

@@ -4784,7 +4786,7 @@ macro_rules! arrays {
47844786
($(#[doc = $ctor:literal] #[doc = $mdn:literal] $name:ident: $ty:ident,)*) => ($(
47854787
#[wasm_bindgen]
47864788
extern "C" {
4787-
#[wasm_bindgen(extends = Object)]
4789+
#[wasm_bindgen(extends = Object, typescript_type = $name)]
47884790
#[derive(Clone, Debug)]
47894791
pub type $name;
47904792

0 commit comments

Comments
 (0)