Skip to content

Instantly share code, notes, and snippets.

@THEtheChad
Last active March 17, 2025 19:35
Show Gist options
  • Save THEtheChad/d759f0f2d93ee63f33df4bf0867e34ff to your computer and use it in GitHub Desktop.
Save THEtheChad/d759f0f2d93ee63f33df4bf0867e34ff to your computer and use it in GitHub Desktop.
type Output = string;
type Input = string;
interface SourceConfig {
uuid: string;
inputs: Input[];
outputs: Output[];
}
type SourceInstanceId<T extends SourceConfig> = string & { config: T };
type Outputs<T extends SourceInstanceId<any>> = T['config']['outputs'];
function createSourceInstance<T extends SourceConfig>(input: T) {
return {
instanceId: JSON.stringify(['source1']) as SourceInstanceId<T>,
};
}
function getOutputs<T extends SourceInstanceId<any>>(instanceId: T) {
// code to retrieve outputs from hashmap
return {
outputs: [] as Outputs<T>,
};
}
const config = {
uuid: 'blah',
inputs: ['input1', 'input2'],
outputs: ['output1', 'output2'],
} as const satisfies SourceConfig;
const instance = createSourceInstance(config);
const { outputs } = getOutputs(instance.instanceId);
// Expected type of outputs is ['output1', 'output2']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment