@radomiej/compiler-types 3.0.9-types.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +1 -0
- package/package.json +27 -0
- package/types/Array.d.ts +280 -0
- package/types/Iterable.d.ts +53 -0
- package/types/Map.d.ts +126 -0
- package/types/Promise.d.ts +647 -0
- package/types/Set.d.ts +74 -0
- package/types/SharedTable.d.ts +4 -0
- package/types/String.d.ts +16 -0
- package/types/Symbol.d.ts +19 -0
- package/types/callMacros.d.ts +88 -0
- package/types/core.d.ts +157 -0
- package/types/eslintIgnore.d.ts +16 -0
- package/types/typeUtils.d.ts +126 -0
package/types/Set.d.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/// <reference no-default-lib="true"/>
|
|
2
|
+
/// <reference types="@rbxts/types"/>
|
|
3
|
+
|
|
4
|
+
interface ReadonlySet<T> extends Iterable<T> {
|
|
5
|
+
/**
|
|
6
|
+
* **DO NOT USE!**
|
|
7
|
+
*
|
|
8
|
+
* This field exists to force TypeScript to recognize this as a nominal type
|
|
9
|
+
* @hidden
|
|
10
|
+
* @deprecated
|
|
11
|
+
*/
|
|
12
|
+
readonly _nominal_Set: unique symbol;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Returns true if empty, otherwise false.
|
|
16
|
+
*/
|
|
17
|
+
isEmpty(this: ReadonlySet<T>): boolean;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Performs the specified action for each (element / pair of elements) in the set
|
|
21
|
+
* @param callbackfn A function that accepts up to three arguments. forEach calls the callbackfn function one time for each (element / pair of elements) in the array.
|
|
22
|
+
*/
|
|
23
|
+
forEach(this: ReadonlySet<T>, callbackfn: (value: T, value2: T, self: ReadonlySet<T>) => void): void;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Returns the number of elements in the set
|
|
27
|
+
*/
|
|
28
|
+
size(this: ReadonlySet<T>): number;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Returns a boolean for whether the given key exists in the set
|
|
32
|
+
*/
|
|
33
|
+
has(this: ReadonlySet<T>, value: T): boolean;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
interface ReadonlySetConstructor {
|
|
37
|
+
new <T>(): ReadonlySet<T>;
|
|
38
|
+
new <T>(values: ReadonlyArray<T>): ReadonlySet<T>;
|
|
39
|
+
}
|
|
40
|
+
declare const ReadonlySet: ReadonlySetConstructor;
|
|
41
|
+
|
|
42
|
+
interface Set<T> extends ReadonlySet<T> {
|
|
43
|
+
/**
|
|
44
|
+
* Adds a value to the set
|
|
45
|
+
*/
|
|
46
|
+
add(this: Set<T>, value: T): this;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Deletes the given key from the set.
|
|
50
|
+
*
|
|
51
|
+
* Returns a boolean indicating whether or not a value was removed.
|
|
52
|
+
*/
|
|
53
|
+
delete(this: Set<T>, value: T): boolean;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Deletes all members of the set.
|
|
57
|
+
*/
|
|
58
|
+
clear(this: Set<T>): void;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
interface SetConstructor {
|
|
62
|
+
new <T>(): Set<T>;
|
|
63
|
+
new <T>(values: ReadonlyArray<T>): Set<T>;
|
|
64
|
+
}
|
|
65
|
+
declare const Set: SetConstructor;
|
|
66
|
+
|
|
67
|
+
/** A Set object with its `__mode` metamethod set to "k" */
|
|
68
|
+
interface WeakSet<T extends object> extends Set<T> {}
|
|
69
|
+
|
|
70
|
+
interface WeakSetConstructor {
|
|
71
|
+
new <T extends object>(): WeakSet<T>;
|
|
72
|
+
new <T extends object>(values: ReadonlyArray<T>): WeakSet<T>;
|
|
73
|
+
}
|
|
74
|
+
declare const WeakSet: WeakSetConstructor;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/// <reference no-default-lib="true"/>
|
|
2
|
+
/// <reference types="@rbxts/types"/>
|
|
3
|
+
|
|
4
|
+
interface String extends Iterable<string> {
|
|
5
|
+
/**
|
|
6
|
+
* **DO NOT USE!**
|
|
7
|
+
*
|
|
8
|
+
* This field exists to force TypeScript to recognize this as a nominal type
|
|
9
|
+
* @hidden
|
|
10
|
+
* @deprecated
|
|
11
|
+
*/
|
|
12
|
+
readonly _nominal_String: unique symbol;
|
|
13
|
+
|
|
14
|
+
/** The current number of characters in the string. */
|
|
15
|
+
size(this: string): number;
|
|
16
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/// <reference no-default-lib="true"/>
|
|
2
|
+
/// <reference types="@rbxts/types"/>
|
|
3
|
+
|
|
4
|
+
interface Symbol {
|
|
5
|
+
/**
|
|
6
|
+
* **DO NOT USE!**
|
|
7
|
+
*
|
|
8
|
+
* This field exists to force TypeScript to recognize this as a nominal type
|
|
9
|
+
* @hidden
|
|
10
|
+
* @deprecated
|
|
11
|
+
*/
|
|
12
|
+
readonly _nominal_Symbol: unique symbol;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface SymbolConstructor {
|
|
16
|
+
readonly iterator: symbol;
|
|
17
|
+
readonly asyncIterator: symbol;
|
|
18
|
+
}
|
|
19
|
+
declare const Symbol: SymbolConstructor;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/// <reference no-default-lib="true"/>
|
|
2
|
+
/// <reference types="@rbxts/types"/>
|
|
3
|
+
|
|
4
|
+
/** Throws an error if the provided value is false or nil. */
|
|
5
|
+
declare function assert<T>(condition: T, message?: string): asserts condition;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Returns the type of the given object as a string. This function works similarly to Lua’s native type function, with
|
|
9
|
+
* the exceptions that Roblox-defined data types like Vector3 and CFrame return their respective data types as strings.
|
|
10
|
+
*/
|
|
11
|
+
declare function typeOf(value: any): keyof CheckableTypes;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Returns true if `typeof(value) == type`, otherwise false.
|
|
15
|
+
* This function allows for type narrowing. i.e.
|
|
16
|
+
* ```
|
|
17
|
+
* // v is unknown
|
|
18
|
+
* if (typeIs(v, "Vector3")) {
|
|
19
|
+
* // v is a Vector3
|
|
20
|
+
* print(v.X, v.Y, v.Z);
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
declare function typeIs<T extends keyof CheckableTypes>(value: any, type: T): value is CheckableTypes[T];
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Returns true if `instance.ClassName == className`, otherwise false.
|
|
28
|
+
*/
|
|
29
|
+
declare function classIs<T extends keyof Instances>(instance: Instance, className: T): instance is Instances[T];
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Returns the passed argument. This function is a macro that compiles to just `arg`.
|
|
33
|
+
*
|
|
34
|
+
* This is useful for ensuring that a value matches the given type in areas where it is not directly possible to do so.
|
|
35
|
+
* @example
|
|
36
|
+
* type P = { x: number, y: number };
|
|
37
|
+
* const obj = {
|
|
38
|
+
* pos: identity<P>({ x: 5, y: 10 });
|
|
39
|
+
* }
|
|
40
|
+
*/
|
|
41
|
+
declare function identity<T>(arg: T): T;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* **Only valid as the expression of a for-of loop!**
|
|
45
|
+
*
|
|
46
|
+
* Used to compile directly to normal Lua numeric for loops. For example,
|
|
47
|
+
* ```ts
|
|
48
|
+
* for (const i of $range(1, 10)) {
|
|
49
|
+
* print(i);
|
|
50
|
+
* }
|
|
51
|
+
* ```
|
|
52
|
+
* will compile into
|
|
53
|
+
* ```lua
|
|
54
|
+
* for i = 1, 10 do
|
|
55
|
+
* print(i)
|
|
56
|
+
* end
|
|
57
|
+
* ```
|
|
58
|
+
*
|
|
59
|
+
* The `step` argument controls the amount incremented per loop. It defaults to `1`.
|
|
60
|
+
*/
|
|
61
|
+
declare function $range(start: number, finish: number, step?: number): Iterable<number>;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* **Only valid as the expression of a return statement!**
|
|
65
|
+
*
|
|
66
|
+
* Compiles directly to a multiple return in Lua. For example,
|
|
67
|
+
* ```ts
|
|
68
|
+
* return $tuple(123, "abc", true);
|
|
69
|
+
* ```
|
|
70
|
+
* will compile into
|
|
71
|
+
* ```lua
|
|
72
|
+
* return 123, "abc", true
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
declare function $tuple<T extends Array<any>>(...values: T): LuaTuple<T>;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Provides the instance tree representation to `path` at runtime.
|
|
79
|
+
*
|
|
80
|
+
* ```ts
|
|
81
|
+
* $getModuleTree("@rbxts/services");
|
|
82
|
+
* ```
|
|
83
|
+
* will, assuming the default rojo game project, compile into
|
|
84
|
+
* ```lua
|
|
85
|
+
* { game:GetService("ReplicatedStorage"), { "rbxts_include", "node_modules", "@rbxts", "services" } }
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
declare function $getModuleTree(module: string): [root: Instance, parts: Array<string>];
|
package/types/core.d.ts
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/// <reference no-default-lib="true"/>
|
|
2
|
+
/// <reference types="@rbxts/types"/>
|
|
3
|
+
/// <reference path="Array.d.ts" />
|
|
4
|
+
/// <reference path="callMacros.d.ts" />
|
|
5
|
+
/// <reference path="Iterable.d.ts" />
|
|
6
|
+
/// <reference path="Map.d.ts" />
|
|
7
|
+
/// <reference path="Promise.d.ts" />
|
|
8
|
+
/// <reference path="Set.d.ts" />
|
|
9
|
+
/// <reference path="SharedTable.d.ts" />
|
|
10
|
+
/// <reference path="String.d.ts" />
|
|
11
|
+
/// <reference path="Symbol.d.ts" />
|
|
12
|
+
/// <reference path="typeUtils.d.ts" />
|
|
13
|
+
/// <reference path="eslintIgnore.d.ts" />
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* **DO NOT USE!**
|
|
17
|
+
*
|
|
18
|
+
* This type only exists because TypeScript requires it!
|
|
19
|
+
*
|
|
20
|
+
* **Use `boolean` instead!**
|
|
21
|
+
*/
|
|
22
|
+
interface Boolean {
|
|
23
|
+
/**
|
|
24
|
+
* **DO NOT USE!**
|
|
25
|
+
*
|
|
26
|
+
* This field exists to force TypeScript to recognize this as a nominal type
|
|
27
|
+
* @hidden
|
|
28
|
+
* @deprecated
|
|
29
|
+
*/
|
|
30
|
+
readonly _nominal_Boolean: unique symbol;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* **DO NOT USE!**
|
|
35
|
+
*
|
|
36
|
+
* This type only exists because TypeScript requires it!
|
|
37
|
+
* @hidden
|
|
38
|
+
* @deprecated
|
|
39
|
+
*/
|
|
40
|
+
interface IArguments {}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* **DO NOT USE!**
|
|
44
|
+
*
|
|
45
|
+
* This type only exists because TypeScript requires it!
|
|
46
|
+
*
|
|
47
|
+
* **Use `number` instead!**
|
|
48
|
+
*/
|
|
49
|
+
interface Number {
|
|
50
|
+
/**
|
|
51
|
+
* **DO NOT USE!**
|
|
52
|
+
*
|
|
53
|
+
* This field exists to force TypeScript to recognize this as a nominal type
|
|
54
|
+
* @hidden
|
|
55
|
+
* @deprecated
|
|
56
|
+
*/
|
|
57
|
+
readonly _nominal_Number: unique symbol;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* **DO NOT USE!**
|
|
62
|
+
*
|
|
63
|
+
* This type only exists because TypeScript requires it!
|
|
64
|
+
*
|
|
65
|
+
* **Use `object` instead!**
|
|
66
|
+
* @hidden
|
|
67
|
+
* @deprecated
|
|
68
|
+
*/
|
|
69
|
+
interface Object {}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* **DO NOT USE!**
|
|
73
|
+
*
|
|
74
|
+
* This type only exists because TypeScript requires it!
|
|
75
|
+
* @hidden
|
|
76
|
+
* @deprecated
|
|
77
|
+
*/
|
|
78
|
+
interface RegExp {}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* **DO NOT USE!**
|
|
82
|
+
*
|
|
83
|
+
* This type only exists because TypeScript requires it!
|
|
84
|
+
*
|
|
85
|
+
* **Use `Callback` instead!**
|
|
86
|
+
*
|
|
87
|
+
* For example,`(a: string, b: number) => boolean` represents a function that takes a `string` and a `number` and
|
|
88
|
+
* returns a `boolean`.
|
|
89
|
+
*
|
|
90
|
+
* More generally, `(a: A, b: B, c: C) => R`, where `A`, `B`, and `C` are different function argument types and `R` is
|
|
91
|
+
* the return type.
|
|
92
|
+
*
|
|
93
|
+
* You can use `void` as a return type for functions that do not return anything: `() => void`
|
|
94
|
+
* @hidden
|
|
95
|
+
* @deprecated
|
|
96
|
+
*/
|
|
97
|
+
interface Function {
|
|
98
|
+
/**
|
|
99
|
+
* **DO NOT USE!**
|
|
100
|
+
*
|
|
101
|
+
* This type only exists because TypeScript requires it!
|
|
102
|
+
* @hidden
|
|
103
|
+
* @deprecated
|
|
104
|
+
*/
|
|
105
|
+
prototype: never;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* **DO NOT USE!**
|
|
110
|
+
*
|
|
111
|
+
* **Use `Callback` instead!**
|
|
112
|
+
*
|
|
113
|
+
* This type only exists because TypeScript requires it!
|
|
114
|
+
* @hidden
|
|
115
|
+
* @deprecated
|
|
116
|
+
*/
|
|
117
|
+
interface CallableFunction extends Function {}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* **DO NOT USE!**
|
|
121
|
+
*
|
|
122
|
+
* **Use `Callback` instead!**
|
|
123
|
+
*
|
|
124
|
+
* This type only exists because TypeScript requires it!
|
|
125
|
+
* @hidden
|
|
126
|
+
* @deprecated
|
|
127
|
+
*/
|
|
128
|
+
interface NewableFunction extends Function {}
|
|
129
|
+
|
|
130
|
+
/** unknown - undefined = defined */
|
|
131
|
+
type defined = {};
|
|
132
|
+
|
|
133
|
+
/** Marker for contextual 'this' type */
|
|
134
|
+
interface ThisType<T> {}
|
|
135
|
+
|
|
136
|
+
/** A function type which is assignable to any other function type (and any function is assignable to). */
|
|
137
|
+
type Callback = (...args: Array<any>) => any;
|
|
138
|
+
|
|
139
|
+
type LuaTuple<T extends Array<any>> = T & {
|
|
140
|
+
/**
|
|
141
|
+
* **DO NOT USE!**
|
|
142
|
+
*
|
|
143
|
+
* This field exists to force TypeScript to recognize this as a nominal type
|
|
144
|
+
* @hidden
|
|
145
|
+
* @deprecated
|
|
146
|
+
*/
|
|
147
|
+
readonly _nominal_LuaTuple: unique symbol;
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
interface TypedPropertyDescriptor<T> {
|
|
151
|
+
value: (self: InferThis<T>, ...parameters: Parameters<T>) => ReturnType<T>;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Marker for non-inference type position
|
|
156
|
+
*/
|
|
157
|
+
type NoInfer<T> = intrinsic;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/// <reference no-default-lib="true"/>
|
|
2
|
+
/// <reference types="@rbxts/types"/>
|
|
3
|
+
|
|
4
|
+
// prettier crashes with `intrinsic` keyword
|
|
5
|
+
|
|
6
|
+
/** Convert string literal type to uppercase */
|
|
7
|
+
type Uppercase<S extends string> = intrinsic;
|
|
8
|
+
|
|
9
|
+
/** Convert string literal type to lowercase */
|
|
10
|
+
type Lowercase<S extends string> = intrinsic;
|
|
11
|
+
|
|
12
|
+
/** Convert first character of string literal type to uppercase */
|
|
13
|
+
type Capitalize<S extends string> = intrinsic;
|
|
14
|
+
|
|
15
|
+
/** Convert first character of string literal type to lowercase */
|
|
16
|
+
type Uncapitalize<S extends string> = intrinsic;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/// <reference no-default-lib="true"/>
|
|
2
|
+
/// <reference types="@rbxts/types"/>
|
|
3
|
+
|
|
4
|
+
/** Placeholder that sometimes helps force TS to display what you want it to. */
|
|
5
|
+
type _<T> = T;
|
|
6
|
+
|
|
7
|
+
/** Make all properties in T optional */
|
|
8
|
+
type Partial<T> = { [P in keyof T]?: T[P] };
|
|
9
|
+
|
|
10
|
+
/** Make all properties in T required */
|
|
11
|
+
type Required<T> = { [P in keyof T]-?: T[P] };
|
|
12
|
+
|
|
13
|
+
/** Make all properties in T readonly */
|
|
14
|
+
type Readonly<T> = { readonly [P in keyof T]: T[P] };
|
|
15
|
+
|
|
16
|
+
/** Make all properties in T non-readonly. */
|
|
17
|
+
type Writable<T> = { -readonly [P in keyof T]: T[P] };
|
|
18
|
+
|
|
19
|
+
/** From T pick a set of properties K */
|
|
20
|
+
type Pick<T, K extends keyof T> = { [P in K]: T[P] };
|
|
21
|
+
|
|
22
|
+
/** Returns a subset of type T which excludes properties K */
|
|
23
|
+
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
|
|
24
|
+
|
|
25
|
+
/** Construct a type with a set of properties K of type T */
|
|
26
|
+
type Record<K extends keyof any, T> = { [P in K]: T };
|
|
27
|
+
|
|
28
|
+
/** Exclude from T those types that are assignable to U */
|
|
29
|
+
type Exclude<T, U> = T extends U ? never : T;
|
|
30
|
+
|
|
31
|
+
/** Extract from T those types that are assignable to U */
|
|
32
|
+
type Extract<T, U> = T extends U ? T : never;
|
|
33
|
+
|
|
34
|
+
/** Returns a union of all the keys of T whose values extend from U */
|
|
35
|
+
type ExtractKeys<T, U> = { [K in keyof T]-?: T[K] extends U ? K : never }[keyof T];
|
|
36
|
+
|
|
37
|
+
/** Returns a new object type of all the keys of T whose values extend from U */
|
|
38
|
+
type ExtractMembers<T, U> = Pick<T, ExtractKeys<T, U>>;
|
|
39
|
+
|
|
40
|
+
/** Returns a union of all the keys of T whose values do not extend from U */
|
|
41
|
+
type ExcludeKeys<T, U> = { [K in keyof T]-?: T[K] extends U ? never : K }[keyof T];
|
|
42
|
+
|
|
43
|
+
/** Returns a new object type of all the keys of T whose values do not extend from U */
|
|
44
|
+
type ExcludeMembers<T, U> = Pick<T, ExcludeKeys<T, U>>;
|
|
45
|
+
|
|
46
|
+
/** Exclude null and undefined from T */
|
|
47
|
+
type NonNullable<T> = T & {};
|
|
48
|
+
|
|
49
|
+
/** Obtain the parameters of a function type in a `tuple | never`. */
|
|
50
|
+
type Parameters<T> = T extends (...args: infer P) => any ? P : never;
|
|
51
|
+
|
|
52
|
+
/** Obtain the parameters of a constructor function type in a `tuple | never` */
|
|
53
|
+
type ConstructorParameters<T extends new (...args: any) => any> = T extends new (...args: infer P) => any ? P : never;
|
|
54
|
+
|
|
55
|
+
/** Obtain the return type of a function type */
|
|
56
|
+
type ReturnType<T> = T extends (...args: Array<any>) => infer R ? R : never;
|
|
57
|
+
|
|
58
|
+
/** Returns the type of `this` for a given function type */
|
|
59
|
+
type InferThis<T> = T extends (this: infer U, ...parameters: Array<any>) => any ? U : never;
|
|
60
|
+
|
|
61
|
+
/** Obtain the return type of a constructor function type */
|
|
62
|
+
type InstanceType<T> = T extends new (...args: Array<any>) => infer R ? R : never;
|
|
63
|
+
|
|
64
|
+
/** Combines a series of intersections into one object, e.g. { x: number } & { y: number } becomes { x: number, y: number } */
|
|
65
|
+
type Reconstruct<T> = _<{ [K in keyof T]: T[K] }>;
|
|
66
|
+
|
|
67
|
+
/** Converts a series of object unions to a series of intersections, e.g. A | B becomes A & B */
|
|
68
|
+
type UnionToIntersection<T> = (T extends object ? (k: T) => void : never) extends (k: infer U) => void ? U : never;
|
|
69
|
+
|
|
70
|
+
/** Extracts the type of the 'this' parameter of a function type, or 'unknown' if the function type has no 'this' parameter. */
|
|
71
|
+
type ThisParameterType<T> = T extends (this: infer U, ...args: Array<any>) => any ? U : unknown;
|
|
72
|
+
|
|
73
|
+
/** Removes the 'this' parameter from a function type. */
|
|
74
|
+
type OmitThisParameter<T> =
|
|
75
|
+
unknown extends ThisParameterType<T> ? T : T extends (...args: infer A) => infer R ? (...args: A) => R : T;
|
|
76
|
+
|
|
77
|
+
/** Given an object `T`, returns a unioned type of all non-readonly property names. */
|
|
78
|
+
type WritablePropertyNames<T> = {
|
|
79
|
+
[K in keyof T]-?: T[K] extends Callback
|
|
80
|
+
? never
|
|
81
|
+
: (<F>() => F extends { [Q in K]: T[K] } ? 1 : 2) extends <F>() => F extends {
|
|
82
|
+
-readonly [Q in K]: T[K];
|
|
83
|
+
}
|
|
84
|
+
? 1
|
|
85
|
+
: 2
|
|
86
|
+
? K
|
|
87
|
+
: never;
|
|
88
|
+
}[keyof T];
|
|
89
|
+
|
|
90
|
+
/** Given an object `T`, returns an object with readonly fields filtered out. */
|
|
91
|
+
type WritableProperties<T> = Pick<T, WritablePropertyNames<T>>;
|
|
92
|
+
|
|
93
|
+
/** Given an Instance `T`, returns a unioned type of all property names. */
|
|
94
|
+
type InstancePropertyNames<T extends Instance> = Exclude<
|
|
95
|
+
ExcludeKeys<T, RBXScriptSignal | Callback | symbol>,
|
|
96
|
+
"Changed"
|
|
97
|
+
>;
|
|
98
|
+
|
|
99
|
+
/** Given an Instance `T`, returns a unioned type of all method names. */
|
|
100
|
+
type InstanceMethodNames<T extends Instance> = ExtractKeys<T, Callback>;
|
|
101
|
+
|
|
102
|
+
/** Given an Instance `T`, returns a unioned type of all event names. */
|
|
103
|
+
type InstanceEventNames<T extends Instance> = ExtractKeys<T, RBXScriptSignal>;
|
|
104
|
+
|
|
105
|
+
/** Given an Instance `T`, returns an object with only properties. */
|
|
106
|
+
type InstanceProperties<T extends Instance> = Pick<T, InstancePropertyNames<T>>;
|
|
107
|
+
|
|
108
|
+
/** Given an Instance `T`, returns an object with only methods. */
|
|
109
|
+
type InstanceMethods<T extends Instance> = Pick<T, InstanceMethodNames<T>>;
|
|
110
|
+
|
|
111
|
+
/** Given an Instance `T`, returns an object with only events. */
|
|
112
|
+
type InstanceEvents<T extends Instance> = Pick<T, InstanceEventNames<T>>;
|
|
113
|
+
|
|
114
|
+
/** Given an Instance `T`, returns an object with readonly fields, methods, and events filtered out. */
|
|
115
|
+
type WritableInstanceProperties<T extends Instance> = WritableProperties<InstanceProperties<T>>;
|
|
116
|
+
|
|
117
|
+
/** Returns a union of all the keys of T which do not start with `_nominal_` */
|
|
118
|
+
type ExcludeNominalKeys<T> = {
|
|
119
|
+
[K in keyof T]-?: K extends `_nominal_${infer _U}` ? never : K;
|
|
120
|
+
}[keyof T];
|
|
121
|
+
|
|
122
|
+
/** Returns a new object type of all the keys of T which do not start with `_nominal_` */
|
|
123
|
+
type ExcludeNominalMembers<T> = Pick<T, ExcludeNominalKeys<T>>;
|
|
124
|
+
|
|
125
|
+
/** Unwraps a Promise<T> */
|
|
126
|
+
type Awaited<T> = T extends PromiseLike<infer U> ? U : T;
|