interface Score {
'1': 'A' | 'B' | 'C' | 'D';
'2': 'A' | 'B' | 'C' | 'D';
'3': 'A' | 'B' | 'C' | 'D';
'4': 'A' | 'B' | 'C' | 'D';
}
const score: Score = {
1: 'A',
2: 'B',
3: 'C',
4: 'D',
};
const scoreWithRecord: Record<'1' | '2' | '3' | '4', 'A' | 'B' | 'C' | 'D'> = {
1: 'A',
2: 'B',
3: 'C',
4: 'D',
};
type Scores = 'A' | 'B' | 'C' | 'D';
type Grades = '1' | '2' | '3' | '4';
const scoreWithTypeRecord: Record<Grades, Scores> = {
1: 'A',
2: 'B',
3: 'C',
4: 'D',
};
interface User {
id: number;
name: string;
age: number;
}
function isValid(user: User): Record<keyof User, boolean> {
const result: Record<keyof User, boolean> = {
id: user.id > 0,
name: user.name !== '',
age: user.age > 0,
};
return result;
}