On the other hand, if you can’t express some shape with an interface and you need to use a union or tuple type, type aliases are usually the way to go. InterfaceĪdding new fields to an existing interfaceĪ type cannot be changed after being createdīecause an interface more closely maps how JavaScript objects work by being open to extension, we recommend using an interface over a type alias when possible. Type AliasesĪs we mentioned, type aliases can act sort of like interfaces however, there are some subtle differences.Īlmost all features of an interface are available in type, the key distinction is that a type cannot be re-opened to add new properties vs an interface which is always extendable. (property) next: LinkedList Try Interfaces vs.
0 Comments
Leave a Reply. |