aptlyundecided / TomatoProgramming

1x 25 minute of programming as often as I can
0 stars 0 forks source link

TypeScript Interface #5

Open aptlyundecided opened 3 years ago

aptlyundecided commented 3 years ago

What is an interface,and what does it do?

aptlyundecided commented 3 years ago

Structural Subtyping!

This is essentially a shape check, on a data type. It's also referred to as Duck Typing.

It's defined in the handbook as being a contract with other parts of a code-base. Even a totally separate code-base, which is what I find interesting. NgRx will be interfacing with a SignalR socket, which is interfacing with a SignalR hub on the C#/.Net side of the world.

But what does it really do under the hood?

aptlyundecided commented 3 years ago

Ok Interesting!

Typescript can inherit an interface as a TYPE, which... honestly makes sense.

It's essentially a "TYPE" of type. Meaning, if "type" is a datatype, then interface would be like an extended class of "type", and if it's not an extension, it's probably VERY similar, but on a different branch of the language model.

aptlyundecided commented 3 years ago

Accidentally closed the issue; WE aren't done here just yet.

aptlyundecided commented 3 years ago

Another cool thing:

Interfaces allow optional properties, read only properties, AND you can extend interfaces with new interfaces. This is fantastic. This will be amazing for handling the data which is coming through the signalR channels, as I have decided that the payloads will be the entire object I am concerned with, and the Client will have the task of sorting through the needed data.

aptlyundecided commented 3 years ago

ALSO

you can interface to functions, indexable types, and classes. This is extremely similar to how C# and Java do things.

I think it's time now for me to create some code, and get a little bit of practice in. It's interesting, I think I'll be able to sort of link together my little training projects if I do a TOUCH of careful planning.

With these interfaces, it may not be necessary.

aptlyundecided commented 3 years ago

Oh before closing issues from here on, I think I should start linking to the code where I learnt them.