What has always bothered me about TypeScript are union types. If you have a function that receives a parameter such as ‘Dog | Cat’, you cannot separate it. For example:
type Dog = { bark: () => void }
type Cat = { meow: () => void }
function speak(animal: Dog | Cat) {
if (‘bark’ in animal) {
animal.bark();
} else {
animal.meow();
}
}Okay, okay, I know you can filter using ‘in’ to see if it has methods, but in real life, in a company where you have a colleague (who is a golden boy) who writes over-engineered code with hundreds of interfaces of interfaces, you don’t want to spend time searching through the files to find every element that is in the union type.
Whereas in Rust it does:
struct Dog { name: String, }
struct Cat { name: String, }
enum Animal {
Dog(Dog),
Cat(Cat),
}fn process_animal(animal: Animal) {
match animal {
Animal::Dog(dog) => {
println!(‘It is a dog named {}’, dog.name);
}
Animal::Cat(cat) => {
println!(‘It is a cat named {}’, cat.name);
}
}
}I think TypeScript should add a couple of lines of code to the generated JavaScript to do something like:
type Dog = { bark: () => void }
type Cat = { meow: () => void }
function speak(animal: Dog | Cat) {
if (animal is Dog) {
animal.bark();
} else {
animal.meow();
}
}For anyone who isn't aware, TypeScript does not use semantic versioning.
Though TypeScript 7.0 will be significant in that it will use the new Go compiler
As a user, I'm of course very excited about v7. As a developer of an app that _integrates_ TypeScript, however, I feel a bit uneasy seeing the API feature still marked as "not ready" on the roadmap.
On the other hand, I can understand leaving it as the last thing to do, after the foundation has set. Also, the TypeScript team has really done an amazing job all these years with backward compatibility, so that is extremely reassuring.
Maybe my uneasiness is just impatience to get to use the sped-up version in my app as well! :)
I am hoping that eventually there will be some agnosticism with the language server. Currently they all seem to rely on Node which in my opinion is rapidly being outclassed by Bun in terms of resource usage. It would be great to eventually be able to pick what runtime they use in VS Code/Cursor to reduce energy drain on my laptop when working on the go.
No way I turn it on. Not a joke.
I had no idea they were using Go to write a compiler.
My deepest thanks to one @AlCalzone for stepping up to Opus port Decorators to tsgo. https://github.com/microsoft/typescript-go/pull/2926
It would have been an affront to have a 6.0 that shipped without the means to work for so so many javascript frameworks/libraries. AlCalzone utterly saving the day.
I also am so so so thankful that maybe perhaps after what felt like a never ending dolldrums, we may finally be getting decorator support in some browsers. What a colossal relief it will be to see the progress of the language become manifest.
> strict is now true by default
I would still have a full head of hair if this had been the case since the beginning. Nonetheless I am glad that we got here in the end.