Is it possible to make the type property depend on the value of name? I tired this, but it doesn't work:
type Attribute<T> = {
name: keyof T;
type: T[keyof T] extends string ? 'a' : 'b';
};
type Item = {
id: string;
date: number;
};
const att1: Attribute<Item> = {
name: 'id',
type: 'a', // this should work
};
const att2: Attribute<Item> = {
name: 'id',
type: 'b', // this should not work
};
const att3: Attribute<Item> = {
name: 'date',
type: 'b', // this should work
};