The purpose of declaration files is to introduce Types in Javascript code and not in Typescript code. In Typescript, you can directly import a types.ts file, or can create your types in the same directory as your code.
Now, coming to your question,
Interface vs Types to declare object types.
Interfaces are created like this
interface Person {
name: string;
age: string;
}
Types are created like this
type Person = {
name: string;
age: string;
}
Both interfaces and types serve a similar purpose except few key differences
- Declaration Merging: Interfaces can be defined multiple times in the same code. The declaration of the interface is merged together to form a single interface by Typescript. This is how it looks
interface Person {
name: string;
}
// it is completely okay to define the same interface again with new or existing
// properties. But the same properties should have the same type.
interface Person {
age: number;
}
// Now, the person interface contains two properties, name and age
Type aliases on the other hand can only be defined once in a code, they cannot be redeclared again. Although you can declare the same type in different files which are treated as local variables. But in the same file, you cannot define a type again.
- Interfaces are open to add new properties
With the help of declaration merging, interfaces allow us to introduce new properties to them, whereas type aliases don't.
Which one is better for Component Props?
I would say both. We can't choose one. But in my personal opinion, I prefer to use interfaces for object declarations, as they go nice with other parts of the code. Since props are only defined once, you can use type as well. It is a personal choice rather than a best practice.
Visit the Typescript Offical Docs to see the differences b/w types and interfaces yourself.