extracted giant typing block
This commit is contained in:
parent
5fd82c1188
commit
dbb35d102f
25
front/src/iframe_api.d.ts
vendored
Normal file
25
front/src/iframe_api.d.ts
vendored
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import type { WorkadventureImport } from './iframe_api';
|
||||||
|
|
||||||
|
type PromiseReturnType<P> = P extends Promise<infer T> ? T : P;
|
||||||
|
type WorkadventureCommandClasses = PromiseReturnType<WorkadventureImport>[number]["default"];
|
||||||
|
type KeysOfUnion<T> = T extends T ? keyof T : never;
|
||||||
|
type ObjectWithKeyOfUnion<Key, O = WorkadventureCommandClasses> = O extends O ? (Key extends keyof O ? O[Key] : never) : never;
|
||||||
|
type ApiKeys = KeysOfUnion<WorkadventureCommandClasses>;
|
||||||
|
type ObjectOfKey<Key extends ApiKeys, O = WorkadventureCommandClasses> = O extends O ? (Key extends keyof O ? O : never) : never;
|
||||||
|
type ShouldAddAttribute<Key extends ApiKeys> = ObjectWithKeyOfUnion<Key>;
|
||||||
|
type WorkadventureFunctions = {
|
||||||
|
[K in ApiKeys]: ObjectWithKeyOfUnion<K> extends Function ? K : never;
|
||||||
|
}[ApiKeys];
|
||||||
|
type WorkadventureFunctionsFilteredByRoot = {
|
||||||
|
[K in WorkadventureFunctions]: ObjectOfKey<K>["addMethodsAtRoot"] extends true ? K : never;
|
||||||
|
}[WorkadventureFunctions];
|
||||||
|
type JustMethodKeys<T> = ({
|
||||||
|
[P in keyof T]: T[P] extends Function ? P : never;
|
||||||
|
})[keyof T];
|
||||||
|
type JustMethods<T> = Pick<T, JustMethodKeys<T>>;
|
||||||
|
type SubObjectTypes = {
|
||||||
|
[importCl in WorkadventureCommandClasses as importCl["subObjectIdentifier"]]: JustMethods<importCl>;
|
||||||
|
};
|
||||||
|
export type WorkAdventureApi = {
|
||||||
|
[Key in WorkadventureFunctionsFilteredByRoot]: ShouldAddAttribute<Key>;
|
||||||
|
} & SubObjectTypes;
|
@ -1,4 +1,5 @@
|
|||||||
import { IframeResponseEventMap, isIframeResponseEventWrapper } from "./Api/Events/IframeEvent";
|
import { IframeResponseEventMap, isIframeResponseEventWrapper } from "./Api/Events/IframeEvent";
|
||||||
|
import type { WorkAdventureApi } from './iframe_api.d';
|
||||||
|
|
||||||
export const registeredCallbacks: { [K in keyof IframeResponseEventMap]?: {
|
export const registeredCallbacks: { [K in keyof IframeResponseEventMap]?: {
|
||||||
typeChecker: Function
|
typeChecker: Function
|
||||||
@ -16,37 +17,7 @@ const importType = Promise.all([
|
|||||||
import("./Api/iframe/Bubble")
|
import("./Api/iframe/Bubble")
|
||||||
])
|
])
|
||||||
|
|
||||||
|
export type WorkadventureImport = typeof importType
|
||||||
type PromiseReturnType<P> = P extends Promise<infer T> ? T : P
|
|
||||||
|
|
||||||
type WorkadventureCommandClasses = PromiseReturnType<typeof importType>[number]["default"];
|
|
||||||
|
|
||||||
type KeysOfUnion<T> = T extends T ? keyof T : never
|
|
||||||
|
|
||||||
type ObjectWithKeyOfUnion<Key, O = WorkadventureCommandClasses> = O extends O ? (Key extends keyof O ? O[Key] : never) : never
|
|
||||||
|
|
||||||
type ApiKeys = KeysOfUnion<WorkadventureCommandClasses>;
|
|
||||||
|
|
||||||
type ObjectOfKey<Key extends ApiKeys, O = WorkadventureCommandClasses> = O extends O ? (Key extends keyof O ? O : never) : never
|
|
||||||
|
|
||||||
type ShouldAddAttribute<Key extends ApiKeys> = ObjectWithKeyOfUnion<Key>;
|
|
||||||
|
|
||||||
type WorkadventureFunctions = { [K in ApiKeys]: ObjectWithKeyOfUnion<K> extends Function ? K : never }[ApiKeys]
|
|
||||||
|
|
||||||
type WorkadventureFunctionsFilteredByRoot = { [K in WorkadventureFunctions]: ObjectOfKey<K>["addMethodsAtRoot"] extends true ? K : never }[WorkadventureFunctions]
|
|
||||||
|
|
||||||
|
|
||||||
type JustMethodKeys<T> = ({ [P in keyof T]: T[P] extends Function ? P : never })[keyof T];
|
|
||||||
type JustMethods<T> = Pick<T, JustMethodKeys<T>>;
|
|
||||||
|
|
||||||
type SubObjectTypes = {
|
|
||||||
[importCl in WorkadventureCommandClasses as importCl["subObjectIdentifier"]]: JustMethods<importCl>;
|
|
||||||
};
|
|
||||||
|
|
||||||
type WorkAdventureApi = {
|
|
||||||
[Key in WorkadventureFunctionsFilteredByRoot]: ShouldAddAttribute<Key>
|
|
||||||
} & SubObjectTypes
|
|
||||||
|
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user