Re:TypeScript’s quirks: How inconsistencies make the languag...
by sjy on Friday January 31, 2020 @11:48PM
(#22208740)
What do you mean by “differentiates the types from the objects”? Could you maybe offer an example comparing TS and C#?
Re:TypeScript’s quirks: How inconsistencies make the languag...
by virtue3 on Thursday February 06, 2020 @04:35PM
(#22260599)
in typescript I have something like
type theThing = { thing1: string, thing2: string };
and the actual object: const thing:Thing = { thing: 'hello', thing2:'more hello' };
"Thing" is not an object, I can't do Thing.new() etc. If I use a class in typescript it behaves just like you would expect C# / Java to.
This allows some really fun stuff with unions where I could do something like
const operateOnThings = (thing: Thing | Thing1 | Thing2) => { //do something based on what kind of thing it is }
Or I can build other types off of it like : type newThing = Pick<Thing, 'thing1'> & { newerThing: number};
Which is something I would have to do a lot of work with interfaces with in order to implement in C#. (I haven't done C# in a few years but I do love the hell out of it).
As someone that's done c/c++/c#/lua/js/ts I've found typescript to be really awesome because it differentiates the types from the objects. Which has given me a much better appreciation of typing rather than the traditional OOP everything.