Last active
March 17, 2025 19:35
-
-
Save THEtheChad/d759f0f2d93ee63f33df4bf0867e34ff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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