Inferring Type for `known` in Tagged Enum Function Argument

hi i have this tagged enum
export type PayloadDataSource<T = unknown> = Data.TaggedEnum<{
  /**
   * The data is explicitly typed and known.
   */
  known: { data: T };

  /**
   * The data type is not specified and can be anything.
   */
  unknown: { data: unknown };
}>

export interface PayloadDataSourceDefinition extends Data.TaggedEnum.WithGenerics<1> {
  readonly taggedEnum: PayloadDataSource<this['A']>;
}

/**
 * Represents the source of a payload's data.
 *
 * - `known`: The data is explicitly typed and known.
 * - `unknown`: The data type is not specified and can be anything.
 */
export const PayloadDataSource = Data.taggedEnum<PayloadDataSourceDefinition>()

and i have this function test(source: PayloadDataSource<{ a: number }>) and i want known to be inferred from source in test function so that when i do test(PayloadDataSource.known({ data: <- this should be typed as '{ a: number }' })
Was this page helpful?