Live data from Hacker News

TypeScript in 5 minutes

typescriptlang.org

11–20 of 33 posts

Re: TypeScript in 5 minutes

#11
post #3

I 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 = Circle | Square | Triangle;
  const myShape: Shape;
  match myShape {
    // uses symbol magic under the hood, eg. if (SymbolShapeCircle in o)
    case (c: Circle) { ... }
    case (other: Triangle | Square) { ... }
  }

Re: TypeScript in 5 minutes

#12
post #8
post #3

I 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…

For types like those which are outside your control you can use type guards[1]: if (value == null) { // TS knows value is null, doesn't let you access value .length for example } else if (Array.isArray(value)) { // TS knows value is an array } else { // TS knows that it's an object here } However, having types like those in your own code (e.g. things like X[] | Y | null) is probably an antipattern and should be avoid…

Deep links:

https://www.typescriptlang.org/docs/handbook/advanced-types....

https://www.typescriptlang.org/docs/handbook/advanced-types....

Re: TypeScript in 5 minutes

#13
Annoying that the site hijacks your back button history like a porn site. What’s up with that? Sure I want to give Typescript (or the equvilent) a try but this feels desperate if not an error.

Re: TypeScript in 5 minutes

#14
post #13

Annoying that the site hijacks your back button history like a porn site. What’s up with that? Sure I want to give Typescript (or the equvilent) a try but this feels desperate if not an error.

TypeScript is one of the fastest-growing technologies in the JS ecosystem right now. It's unlikely the team is using the back button behavior as a way to get membership.

Incidentally, to which porn sites are you referring? Which of your favorite porn sites do you think do the best job with UI/UX?

Re: TypeScript in 5 minutes

#15
post #2

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.

Re: TypeScript in 5 minutes

#17

Genuinely curious. Does anyone use the command line `tsc` to compile typescript in everyday work? Or is it more of just a learning stepping stone?

Depends on your IDE. In practice, tsc is a build step in CI/CD, not a dev tool (if you’re using a good IDE).

Re: TypeScript in 5 minutes

#18

Genuinely curious. Does anyone use the command line `tsc` to compile typescript in everyday work? Or is it more of just a learning stepping stone?

I use cc instead of make, and javac instead of Gradle fairly often for various purposes like debugging or experimenting. Is the js world different?

Re: TypeScript in 5 minutes

#19

Genuinely curious. Does anyone use the command line `tsc` to compile typescript in everyday work? Or is it more of just a learning stepping stone?

in a project I worked on, we used tsc with msbuild to build our frontend.

Re: TypeScript in 5 minutes

#20

Genuinely curious. Does anyone use the command line `tsc` to compile typescript in everyday work? Or is it more of just a learning stepping stone?

I use tsc -w, what do you use? I'm not using it on the frontend but for nodejs (i would use webpack on the frontend)
Post reply on HN