Live data from Hacker News

TypeScript 3.5

devblogs.microsoft.com

1–10 of 88 posts

Re: TypeScript 3.5

#2
I would really love to enjoy TypeScript, especially now that they've added HKTs, but I am constantly running into type errors when the types clearly match, leading to weird workaround code where the type of some key in some object is specified as:

false | 'x' | 'y' | undefined

Meaning passing in `'x'` should work just fine. But instead, it specializes it to just a string, then throws a type error. The workaround requires me to write the following value to avoid a type error:

'x' as 'x'

This is not the only time I've run into this kind of problem -- I run into this problem regularly -- this is just the simplest version of it that I've experienced. I just cannot take a type system seriously when workarounds like that are needed.

Add to that, in many cases being unable to import a JS library in that doesn't include typedefs, and I fail to see how TS can be considered a superset of JS. It's certainly sold that way, but it's clearly not totally true. TS+React requires --noImplicitAny, which cannot be worked around (it's labeled as being required due to a platform limitation).

I also find Microsoft's documentation of TypeScript to be very poor (and has no search feature -- I'm sure they have some convenient excuse for that). I tend to learn how things work from random Github comments or source code after reading the documentation over and over. What is `declare` used for in practice? They don't really say, they just say it's for declaring things, and give highly specific examples.

Maybe I'm the odd one here and maybe I'm missing some piece of information that a lot of TypeScript developers have, but I've yet to find it and given all the choice I have these days, there are numerous languages I would choose well before TypeScript.

Re: TypeScript 3.5

#3
post #2

I would really love to enjoy TypeScript, especially now that they've added HKTs, but I am constantly running into type errors when the types clearly match, leading to weird workaround code where the type of some key in some object is specified as: false | 'x' | 'y' | undefined Meaning passing in `'x'` should work just fine. But instead, it specializes it to just a string, then throws a type error. The workaround requ…

> I just cannot take a type system seriously when workarounds like that are needed.

Are you familiar with type theory and how easy it is for a type system to require too much work to be useful? Especially with conditional types. TypeScript has been doing a phenomenal job.

For this particular use case, since version 3.4 you can write `'x' as const` which will work no matter how large your type is.

Re: TypeScript 3.5

#4
post #2

I would really love to enjoy TypeScript, especially now that they've added HKTs, but I am constantly running into type errors when the types clearly match, leading to weird workaround code where the type of some key in some object is specified as: false | 'x' | 'y' | undefined Meaning passing in `'x'` should work just fine. But instead, it specializes it to just a string, then throws a type error. The workaround requ…

Try `as const`?

Re: TypeScript 3.5

#6
post #5

Typescript 3.5: fixing the problems we introduced and providing workarounds for new features in a broken type system.

No kidding. I thought you were being facetious but reading the changelog it's clear that most of these would typically have been in a high-priority 3.4.1 release as a number of them are blocking (now there's code that compiled under 3.4 with nary a warning that won't compile under 3.5).

Re: TypeScript 3.5

#7
Wonderful! My favorites from this release:

- Omit helper type

- Smart Select (allows editor to expand/shrink selection based on syntactic construct)

- Extract to type alias (smart refactor of function parameters to their own type)

- Performance improvements

Re: TypeScript 3.5

#8
post #3
post #2

I would really love to enjoy TypeScript, especially now that they've added HKTs, but I am constantly running into type errors when the types clearly match, leading to weird workaround code where the type of some key in some object is specified as: false | 'x' | 'y' | undefined Meaning passing in `'x'` should work just fine. But instead, it specializes it to just a string, then throws a type error. The workaround requ…

> I just cannot take a type system seriously when workarounds like that are needed. Are you familiar with type theory and how easy it is for a type system to require too much work to be useful? Especially with conditional types. TypeScript has been doing a phenomenal job. For this particular use case, since version 3.4 you can write `'x' as const` which will work no matter how large your type is.

Speaking of which, is there any tutorials on type theory that targets developers instead of mathematicians?

Re: TypeScript 3.5

#9
post #5

Typescript 3.5: fixing the problems we introduced and providing workarounds for new features in a broken type system.

Could you help me specify why TS is a broken type system ? Thanks you very much.

Re: TypeScript 3.5

#10
post #2

I would really love to enjoy TypeScript, especially now that they've added HKTs, but I am constantly running into type errors when the types clearly match, leading to weird workaround code where the type of some key in some object is specified as: false | 'x' | 'y' | undefined Meaning passing in `'x'` should work just fine. But instead, it specializes it to just a string, then throws a type error. The workaround requ…

I second that, to a degree. I write mostly TypeScript and Rust these days and it still behaves unexpectedly sometimes.

Example: for a service we wanted to port Rusts’ Result.

https://gist.github.com/KenanSulayman/34a40daa3ebbd1e1bdf7c7...

Notice the ‘as any’ and ‘_T!: T;’ et al. hacks to make it work.

Other than that it’s completely a one to one port from the Rust core implementation.

Post reply on HN