Как сделать эту компиляцию без ошибок? Мы используем TypeScript 2.9.1.
interface IFoo {
type: 'foo';
foo: string;
}
interface IBar {
type: 'bar';
bar: string;
}
type FooBar = IFoo | IBar;
class Getter<T extends FooBar> {
private data: T;
constructor(data: T) {
this.data = data;
}
public getMe(): string {
const { data } = this;
// Property 'foo' does not exist on type 'T'.
// Property 'bar' does not exist on type 'T'.
return data.type === 'foo' ? data.foo : data.bar;
}
}