Article should mention that TypeScript is made by Microsoft.
this seems to be highly downvoted as i suppose people are reading it as a rude aside, but I read it as a feature worth highlighting. Microsoft has an excellent track record with language design, promotion, stability, and tooling.
TypeScript in 5 minutes
21–30 of 33 posts
Re: TypeScript in 5 minutes
#22Re: TypeScript in 5 minutes
#23Genuinely curious. Does anyone use the command line `tsc` to compile typescript in everyday work? Or is it more of just a learning stepping stone?
"compile": "tsc -p ./tsconfig.json",
I also have a start script, for running it from the command line: "start": "npm run compile && node ./.build/main.js"
tsc has some kind of file-watching mode, that I assume compiles when you save stuff, but I don't use that, because I'm not a monster.Re: TypeScript in 5 minutes
#24Shouldn't the `Student` class implement `Person` here? Did I miss that in the code sample?
The public modifier on these constructor parameters is actually introducing them as properties of the Student type:
constructor(public firstName: string, public middleInitial: string, public lastName: string) {}
Since the Student type has 'firstName' and 'lastName' properties, it meets the Person interface requirements. It doesn't need to declare that it is, but could and usually would just for readability and the additional assurance that you haven't forgotten something.
Re: TypeScript in 5 minutes
#25What’s scary is the number of bugs in the original implementation! I made the comment on Reactuflux’s #typescript channel that I’m afraid to use code not written in TS now.
Anyway, it’s been interesting coming from the land of Python, and surprisingly quite enjoyable.
The Bulma library I’ve re-written and released on npm is https://www.npmjs.com/package/rbx
Re: TypeScript in 5 minutes
#26Genuinely curious. Does anyone use the command line `tsc` to compile typescript in everyday work? Or is it more of just a learning stepping stone?
With the disclaimer that I don't get paid for my Typescript work (I use it for some personal projects, as it saves me a bit of time compared to C++), I have this as the compile scripts entry in my package.json: "compile": "tsc -p ./tsconfig.json", I also have a start script, for running it from the command line: "start": "npm run compile && node ./.build/main.js" tsc has some kind of file-watching mode, that I assume…
Re: TypeScript in 5 minutes
#27Genuinely curious. Does anyone use the command line `tsc` to compile typescript in everyday work? Or is it more of just a learning stepping stone?
Re: TypeScript in 5 minutes
#28I just started a side project with Typescript, and I like a lot of it, but, ironically, type discovery seems _very_ lacking. The JS keywords like `instanceof` are useless because everything is just an object, and Typescript doesn't give you a way to pattern match on types. For example, in React there is this type that's a union of an array, single object or null. Some kind of catch-all, I guess. So, when you see one…
Good call. I love TypeScript, and wouldn't build a web app of even small scope without a typing solution at least as good as TypeScript, and it's the best. But, as you say, pattern matching sum types is a weak point in practical use of TypeScript. Since the types only exist at compile time, maybe there could be a heavier opt-in system that uses something like Symbols to do pattern matching: matchable type Shape = Cir…
interface Tagged {
tag: string;
}
interface Circle extends Tagged {
tag: 'circle'
}
// ... Other implementations
switch (myShape.tag) {
case 'circle': {
// Do circular things
}
// etc . . .
}
You'll occasionally even see this in Scala code, since the @switch annotation optimizes pattern-match statements[2].1. https://www.typescriptlang.org/docs/handbook/advanced-types....
2. https://www.scala-lang.org/api/2.12.x/scala/annotation/switc...
Re: TypeScript in 5 minutes
#29Shouldn't the `Student` class implement `Person` here? Did I miss that in the code sample?
No, you don't need to inherit or implement which is one of the great features of TypeScript!
In this example, the `greeter` function accepts any object that has a `firstName` and `lastName` property defined, regardless of what the object/type is called. No need for inheritance.
In fact, the `Person` interface is not even emitted in the JS output because interfaces are only used at compile time, not at run time.
Re: TypeScript in 5 minutes
#30I just started a side project with Typescript, and I like a lot of it, but, ironically, type discovery seems _very_ lacking. The JS keywords like `instanceof` are useless because everything is just an object, and Typescript doesn't give you a way to pattern match on types. For example, in React there is this type that's a union of an array, single object or null. Some kind of catch-all, I guess. So, when you see one…
What you're "missing", I think, is that Typescript's types only exist at compile-time, so they aren't available through runtime operations like instanceof. It's like a more extensive case of Java generics erasure.