An interface can also extend another interface. Not only that, but also some (but not all) types. The rule of thumb here is: if the type is well-known and could be written as an interface, it can be extended.pic.twitter.com/HyO0GgGOEW
U tweetove putem weba ili aplikacija drugih proizvođača možete dodati podatke o lokaciji, kao što su grad ili točna lokacija. Povijest lokacija tweetova uvijek možete izbrisati. Saznajte više
An interface can also extend another interface. Not only that, but also some (but not all) types. The rule of thumb here is: if the type is well-known and could be written as an interface, it can be extended.pic.twitter.com/HyO0GgGOEW
Another feature or Interfaces are index signatures. Interfaces can be indexed only by string or number, not by union types. You need Mapped Types for that. If you index by string and number, the value indexed by number has to be a subset of the value indexed by string.pic.twitter.com/Mq7QKpvcZa
Interfaces are evaluated lazily. That allows for recursion that might not be possible with types. Since TS3.7, types have become "lazier" and they allow for most recursion, too. Just remember, if something doesn't work as a type, an interface might still work fine.pic.twitter.com/cl8Siz7Ike
The lazy nature of interfaces has an additional benefit:
Types, as they are eager, often display all their definition in error messages, exposing implementation details.
Interfaces just show their name.
We used this in #redux-toolkit got get more legible autocompletion & errors.pic.twitter.com/FvnMAAAw2t
Next week we'll start on types.
I hope you've learned something today, and I'll see you next #TypeScriptTuesday.
You can find all examples in a TypeScript playground here: https://www.typescriptlang.org/play/#code/LAKAlgdgLgpgTgMwIYGMYAICCKpgPYToDeo66UAngA4wBc6AzlHJAOYDcoAvqLyCSDKRYiVBgDqYKAAsAonDh44mKMzAAjAK6xipMuniK49eUc6D0PEHoD0NgwA9YEACZt0AW00AbXFW8YwvDIaAzoYGFUeAwMGgF6QaJo6ADKahCsAApIFN54SC7YuASSMqZKjs4uYUX4EAA06KVyCkoqalo6AvroVDl5BfRMLBnmZFa2AFSTeuiT6AAq0hHoKEiE6hhwMAx43gBuMC7keMTk1HSM6Ry9-fkuQ9eWjQDuyyjSs-MoeD7Hm44qNsYkd0EgwutwtBgmJGrtwlBVpCATAnDBXEcAHRfGwJaFJDBpEZZO4FWoESro6roADyHikAB4iWxsrl7uSIM1ynBGgAiQxKXkAPl0FjIHhgUCQ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the fact that interfaces can merge! It’s not a feature used frequently in user-land code, but it’s super helpful when writing library code/typings that might interact with other libraries.
Interface merging was very surprising to me, coming from a Java background but after initial shock can see how it makes a lot of sense in JS. Would be nice if IDEs gave a visual hint when an interface is part of a merge.
Twitter je možda preopterećen ili ima kratkotrajnih poteškoća u radu. Pokušajte ponovno ili potražite dodatne informacije u odjeljku Status Twittera.