This is quite verbose:
interface Point {
x: 1;
y: 2;
}
const point: Point = {
x: 1,
y: 2,
};
// The inferred type would have been
interface Point {
x: number;
y: number;
}
Is there any way to use type inference here but to force keys to be literals?
>Solution :
Numbers are not strings :
const point = {
x: '1',
y: '2',
} // { x: string; y: string; }
const point = {
x: 1,
y: 2,
} // { x: number; y: number; }
And if you want them as literals, use as const
const point = {
x: '1',
y: '2',
} as const; // { x: '1'; y: '2'; }