diff --git a/packages/frontend-internal/src/wiring/OpaqueType.ts b/packages/frontend-internal/src/wiring/OpaqueType.ts index abd74bd910..3d05b619bc 100644 --- a/packages/frontend-internal/src/wiring/OpaqueType.ts +++ b/packages/frontend-internal/src/wiring/OpaqueType.ts @@ -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( + createInstance< + TVersion extends T['versions']['version'], + TPublic extends T['public'], + >( version: TVersion, props: Omit & (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'] { diff --git a/packages/frontend-plugin-api/src/wiring/createExtension.ts b/packages/frontend-plugin-api/src/wiring/createExtension.ts index 4941324bed..ac7b1de432 100644 --- a/packages/frontend-plugin-api/src/wiring/createExtension.ts +++ b/packages/frontend-plugin-api/src/wiring/createExtension.ts @@ -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>; - }; - configInput: string extends keyof TConfigSchema - ? {} - : z.input< - z.ZodObject<{ - [key in keyof TConfigSchema]: ReturnType; - }> - >; - 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 + >; + }; + configInput: string extends keyof TConfigSchema + ? {} + : z.input< + z.ZodObject<{ + [key in keyof TConfigSchema]: ReturnType; + }> + >; + 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; }, - }) as ExtensionDefinition; + }); }