frontend-internal: loosen type of opaqueType.createInstance return value

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2024-09-11 17:19:47 +02:00
parent bb0ea523b9
commit dadb506586
2 changed files with 28 additions and 25 deletions
@@ -122,7 +122,10 @@ export class OpaqueType<
* @param value The remaining public and internal properties of the instance
* @returns An instance of the opaque type
*/
createInstance<TVersion extends T['versions']['version']>(
createInstance<
TVersion extends T['versions']['version'],
TPublic extends T['public'],
>(
version: TVersion,
props: Omit<T['public'], '$$type'> &
(T['versions'] extends infer UVersion
@@ -131,12 +134,12 @@ export class OpaqueType<
: never
: never) &
Object, // & Object to allow for object properties too, e.g. toString()
): T['public'] {
): TPublic {
return {
...(props as object),
$$type: this.#type,
...(version && { version }),
} as T['public'];
} as unknown as TPublic;
}
#isThisInternalType(value: unknown): value is T['public'] & T['versions'] {
@@ -366,26 +366,6 @@ export function createExtension<
namespace: string | undefined extends TNamespace ? undefined : TNamespace;
name: string | undefined extends TName ? undefined : TName;
}> {
type T = {
config: string extends keyof TConfigSchema
? {}
: {
[key in keyof TConfigSchema]: z.infer<ReturnType<TConfigSchema[key]>>;
};
configInput: string extends keyof TConfigSchema
? {}
: z.input<
z.ZodObject<{
[key in keyof TConfigSchema]: ReturnType<TConfigSchema[key]>;
}>
>;
output: UOutput;
inputs: TInputs;
kind: string | undefined extends TKind ? undefined : TKind;
namespace: string | undefined extends TNamespace ? undefined : TNamespace;
name: string | undefined extends TName ? undefined : TName;
};
const schemaDeclaration = options.config?.schema;
const configSchema =
schemaDeclaration &&
@@ -398,7 +378,27 @@ export function createExtension<
);
return OpaqueExtensionDefinition.createInstance('v2', {
T: undefined as unknown as T,
T: undefined as unknown as {
config: string extends keyof TConfigSchema
? {}
: {
[key in keyof TConfigSchema]: z.infer<
ReturnType<TConfigSchema[key]>
>;
};
configInput: string extends keyof TConfigSchema
? {}
: z.input<
z.ZodObject<{
[key in keyof TConfigSchema]: ReturnType<TConfigSchema[key]>;
}>
>;
output: UOutput;
inputs: TInputs;
kind: string | undefined extends TKind ? undefined : TKind;
namespace: string | undefined extends TNamespace ? undefined : TNamespace;
name: string | undefined extends TName ? undefined : TName;
},
kind: options.kind,
namespace: options.namespace,
name: options.name,
@@ -510,5 +510,5 @@ export function createExtension<
},
}) as ExtensionDefinition<any>;
},
}) as ExtensionDefinition<T>;
});
}