TH | when to use | limit | TH | TH |
---|---|---|---|---|
type | use it by default | no | TD | TD |
interface | need to use extends ; working with objects that inherit from each other; |
can’t express unions, mapped types, or conditional type; Interfaces with the same name in the same scope merge their declarations, leading to unexpected bugs; | TD | TD |
type WithId = {
id: string;
};
type User = WithId & {
name: string;
};
This is perfectly fine code, but it’s slightly less optimal. The reason is to do with the speed at which TypeScript can check your types.
We could add ESLint to your project and turn on the no-redeclare rule.
nx:
{
files: ['*.ts', '*.tsx'],
extends: ['plugin:@nx/typescript'],
rules: {
'no-redeclare': 'error',
},
},