Type & Interface ?
Type & Interface ?
Github: Gagan-Saini-GS
@gagan-saini-gs
Interface
Why Different?
Type
Created By
Gagan Saini 0
Gagan Saini
Github: Gagan-Saini-GS
@gagan-saini-gs
Interface
Object Shape Definition
They are primarily used for defining the shape
of objects.
Compatibility
It’s declarations are open-ended, meaning that
you can add new properties to an interface later
without causing compatibility issues with
existing code that uses that interface.
Created By
Gagan Saini 1
Gagan Saini
Github: Gagan-Saini-GS
@gagan-saini-gs
Declaration Merging
It support declaration merging, meaning that
multiple interface declarations with the same
name are merged into a single interface.
Extensibility
It support extending other interfaces, allowing
you to create more complex and reusable type
definitions by combining multiple interfaces.
Created By
Gagan Saini 2
Gagan Saini
Github: Gagan-Saini-GS
@gagan-saini-gs
Code Example
Created By
Gagan Saini 3
Gagan Saini
Github: Gagan-Saini-GS
@gagan-saini-gs
Type
Flexible Shape Definition
Type aliases allow you to define any kind of
type, not just objects.
Created By
Gagan Saini 4
Gagan Saini
Github: Gagan-Saini-GS
@gagan-saini-gs
Expressiveness
Type aliases are more expressive than
interfaces in some cases, especially when
dealing with complex types or conditional
types.
Readability
Type aliases can be more concise and easier to
read than interfaces, particularly for complex
types or when defining types inline.
Created By
Gagan Saini 5
Gagan Saini
Github: Gagan-Saini-GS
@gagan-saini-gs
Code Example
Created By
Gagan Saini 6
Gagan Saini
Github: Gagan-Saini-GS
@gagan-saini-gs
Summary
Interfaces are typically used for defining the
shape of objects, supporting extension and
declaration merging,
Created By
Gagan Saini 7
Gagan Saini
Github: Gagan-Saini-GS
@gagan-saini-gs