interface OrderExtended extends Order {
xp: OrderXp | null
export interface OrderXp {
isCool: boolean
isAwesome: boolean
maybeIsBoth: boolean
From TS docs:
“As we mentioned, type aliases can act sort of like interfaces; however, there are some subtle differences.
One difference is that interfaces create a new name that is used everywhere. Type aliases don’t create a new name — for instance, error messages won’t use the alias name. In the code below, hovering over interfaced in an editor will show that it returns an Interface, but will show that aliased returns object literal type.“
This is why we prefer interfaces. It makes everything more readable.
"=" is already odd, different from classes and all other non-object "{ ... }" statements.
Also, almost no non-advanced training material I can remember talks about "type"..
Running a Dev shop, why overload people's brains with something that looks archaic and has questionable use (at least for business applications)?
Also everyone has lots of historic interface/class/type/structure luggage from other languages that doesn't map into using types in place of interfaces.
I imagine there's valid use for it for dev tool creators.
a) What is your reason behind it?
b) Why archaic is a bad thing? Math notation of plus is archaic, let's change the notation?
I feel like people who have background in Java, C# would be more comfortable with notation of interface.
People who have background in functional languages, like OCaml (all ML family?) will prefer type notation.
People who don't have background - will accept whatever you show them first.
Argument "=" is already odd
is a matter of taste. And if you don't like it based on that, there is no reason for me to argue. There are people who prefer to put semicolons in the end of JS and who don't...
I also disagree with this, I think for one an interface
in the OO world conveys the message that somewhere you're going to have an implementation of sorts and when you don't have at least one of those that is not being explicit.
I would also argue that an interface
conveys the message of abstraction which is not the case when one would use it to define the structure of an object which a type
does a much better of.
I think a type
is very explicit in that sense.
Also, you say that type
is archaic, well, it's not, it is used in many other languages (modern languages) to represent exactly that.
I had a similar experience, which led me to open a PR for the Typescript handbook, documenting using type aliases over interfaces.
github.com/microsoft/TypeScript-Ha...
class Parrot implements IClassyAnimal {
name: string;
constructor(name: string) {
this.name = name;
// Class 'Parrot' incorrectly implements interface 'IClassyAnimal'.
// Type 'Parrot' provides no match for the signature 'new (name: string): this'.
class MadeFromString implements ComesFromString {
constructor (public name: string) {
console.log('ctor invoked');
function makeObj(n: StringConstructable) {
return new n('hello!');
class Parrot implements IClassyAnimal {
name: string;
constructor(name: string) {
this.name = name;
Yes. I wasn't unable to check it, but I was sure I did something like that. But according to the docs
typescriptlang.org/docs/handbook/i...
Seems like you are right. Constructors interfaces declarations are mostly effective as function arguments.
Built on Forem — the open source software that powers DEV and other inclusive communities.
Made with love and Ruby on Rails. DEV Community © 2016 - 2024.