Created
November 29, 2019 16:31
-
-
Save Tirke/d95d3da7b79f1dc7d1f3adbf25710de3 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 Config<T> = | |
T extends { type: 'sftp' } ? { login: string, password: string } : | |
T extends { type: 'post' } ? { url: string, header: string } : {}; | |
const union: { type: 'post' | 'sftp' } = { type: 'post' } | |
const simple: { type: 'post' } = { type: 'post' } | |
const splitUnion: { type: 'post' } | { type: 'sftp' } = { type: 'post' } | |
type Instance = Config<typeof union> // ==> Instance is {} and not {url: string, header: string} | |
type InstanceOk = Config<typeof simple> // ==> Instance is { url: string, header: string } | |
type InstanceOk2 = Config<typeof splitUnion> // ==> Instance is { url: string, header: string } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment