конкретный тип?
https://www.typescriptlang.org/play/#src=type%20Foo%20%3D%20%7B%0D%0A%20%20%20%20kind%3A%20'foo'%0D%0A%20%20%20%20prop%3A%20string%0D%0A%7D%0D%0A%0D%0Atype%20Bar%20%3D%20%7B%0D%0A%20%20%20%20kind%3A%20'bar'%2C%0D%0A%20%20%20%20prop%3A%20number%3B%0D%0A%7D%0D%0A%0D%0Atype%20FooBar%20%3D%20Foo%20%7C%20Bar%3B%0D%0A%0D%0A%0D%0Atype%20DiscriminateUnion%3CT%2C%20K%20extends%20keyof%20T%2C%20V%20extends%20T%5BK%5D%3E%20%3D%20%0D%0A%20%20%20%20T%20extends%20Record%3CK%2C%20V%3E%20%3F%20T%20%3A%20never%0D%0A%20%20%0D%0Atype%20MapDiscriminatedUnion%3CT%20extends%20Record%3CK%2C%20string%3E%2C%20K%20extends%20keyof%20T%3E%20%3D%0D%0A%20%20%7B%20%5BV%20in%20T%5BK%5D%5D%3A%20DiscriminateUnion%3CT%2C%20K%2C%20V%3E%20%7D%3B%0D%0A%0D%0A%2F%2F%20type%20MappedFooBar%20%3D%20MapDiscriminatedUnion%3CFooBar%2C%20'kind'%3E%3B%0D%0A%2F%2Ftype%20Picked%20%3D%20Pick%3CMappedFooBar%2C%20'bar'%3E%5B'bar'%5D%0D%0A%0D%0Atype%20MappedT%3CT%20extends%20Record%3Cany%2C%20any%3E%3E%20%3D%20MapDiscriminatedUnion%3CT%2C%20'kind'%3E%0D%0A%0D%0Atype%20PickFromUnion%3CT%20extends%20any%2C%20K%3E%20%3D%20Pick%3CMappedT%3CT%3E%2C%20'bar'%3E%5B'bar'%5D%0D%0A%0D%0Atype%20res%20%3D%20PickFromUnion%3CFooBar%2C%20'bar'%3E
Обсуждают сегодня