Если вам кажется, что сообщения об ошибках в TS могли бы быть более понятными, вы не одни. Одного из соавторов xstate это утомило, и он сделал расширение для vscode, декодирующее ошибки с майкрософтового на английский. Штука, конечно, маргинально полезная, но кому-то, может, и поможет. Потестить без установки можно тут.
Forwarded from artalog (artalar)
Как же у меня бомбит с тайпскриптовых енумов.
Мало того что они используют зарезервированное в ЖС слово (что обязательно в какой-то момент сломается), так и реализованы криво и имеют плохой интероп с остальными типами / значениями и в общем ощущаются как очень странный костыль вместо юнионов.
Главная практическая проблема в них, для меня, в том что их нельзя мапить на уровне типов, те дженерик операции над енумами практически невозможны. Какие-то гиперболизированные, но бесполезные unique type, но иногда не unique 🤪
Мало того что они используют зарезервированное в ЖС слово (что обязательно в какой-то момент сломается), так и реализованы криво и имеют плохой интероп с остальными типами / значениями и в общем ощущаются как очень странный костыль вместо юнионов.
Главная практическая проблема в них, для меня, в том что их нельзя мапить на уровне типов, те дженерик операции над енумами практически невозможны. Какие-то гиперболизированные, но бесполезные unique type, но иногда не unique 🤪
readonly добавили, а nonenumerable забыли :)
https://github.com/microsoft/TypeScript/issues/9726
https://www.typescriptlang.org/play?#code/MYewdgzgLgBATgU2FAjDAvDAJiYBXAWwTCgDoAjELAT1IHMEoAhEPMLASzDoGEAbDsSgAlJFAAUASgDcAWABQoSLETIATBhgBvUrtWoAvnPkB6EzGABDMGBAqElrDAAOcEM4Rwo1GAAMoIADKUHBcdL4wIABmfmxYCFFcCFi+CkoQIHwIpHwgdOL6aqQAHqQBwaHcUjJAA
https://github.com/microsoft/TypeScript/issues/9726
https://www.typescriptlang.org/play?#code/MYewdgzgLgBATgU2FAjDAvDAJiYBXAWwTCgDoAjELAT1IHMEoAhEPMLASzDoGEAbDsSgAlJFAAUASgDcAWABQoSLETIATBhgBvUrtWoAvnPkB6EzGABDMGBAqElrDAAOcEM4Rwo1GAAMoIADKUHBcdL4wIABmfmxYCFFcCFi+CkoQIHwIpHwgdOL6aqQAHqQBwaHcUjJAA
https://www.typescriptlang.org/play?#code/GYVwdgxgLglg9mABBBECGUAqB3OBlKAJxjAHMBnACnIC5FyiTSBKAbwChCBTKEQpcgDoUkDJQBE5OAFsuAeSgALLoQLEy45gG52AX3bsIAGzTlyiAIIXEHAJAiGhENDiFKzG-tukeapu5t2W1tuXn5ESUYNHVt9fUMTM0QAIWTELgAPKC4wABNzK0DvXyjSdzpHJhifKD8ySjQ6MBBpACMVZiaW9sJqkvUytAB+LraOitLEAB9EZrHCIpCePiQARhi49iMeRFbEAF5ZrmwU5PcdLZ2pWTrSA93BGtvzgwc4bcEjODKoAE8ABy4cGA9BkXFu2leCCkHy+ZRE6CwuFuVGu4NKzEhQA
Thanks @brutor
A simpler example of the same issue from @djaler: https://www.typescriptlang.org/play?#code/GYVwdgxgLglg9mABAcwKZQMpQE4zMgCgEoAuRAZxz2QG4AoUSWBFdLXfAgQzLBAFsARqmylEfISPqNo8JGkxVOXAPy8Bw0WUodkiAD7iNIxAG86ASGzoQ2JAEZ6AXzp0ICSomBw4iALysirrE9Aw+AHTukFxQBADkglzYcURAA
Thanks @brutor
A simpler example of the same issue from @djaler: https://www.typescriptlang.org/play?#code/GYVwdgxgLglg9mABAcwKZQMpQE4zMgCgEoAuRAZxz2QG4AoUSWBFdLXfAgQzLBAFsARqmylEfISPqNo8JGkxVOXAPy8Bw0WUodkiAD7iNIxAG86ASGzoQ2JAEZ6AXzp0ICSomBw4iALysirrE9Aw+AHTukFxQBADkglzYcURAA
Strict option does not override underlying options like noImplicitAny in extended configs
Global declarations aren’t saved, but there is no other way to infer it. TS doesn’t respect JS standards.
Edit. TS claims to have a design goal of typing common JS patterns. The pattern in question is typeof of undeclared variable. Probably every reader used to do
It's currently possible to declare the variable globally by extending Window interface, but those declarations will be available — well — everywhere, including the modules that have nothing to do with them. Global variables, global declarations, all the globals are widely considered an antipattern for this reason.
Narrowing already makes it so that single variable can have several types in different parts of the code, but correctly typed typeof would also require dynamically changing a set of variables that are available in current scope.
It weren't us who made a decision about design goals, so the discussion on unintended consequences is under the feature request.
Edit. TS claims to have a design goal of typing common JS patterns. The pattern in question is typeof of undeclared variable. Probably every reader used to do
typeof window !== 'undefined'
at least once.It's currently possible to declare the variable globally by extending Window interface, but those declarations will be available — well — everywhere, including the modules that have nothing to do with them. Global variables, global declarations, all the globals are widely considered an antipattern for this reason.
Narrowing already makes it so that single variable can have several types in different parts of the code, but correctly typed typeof would also require dynamically changing a set of variables that are available in current scope.
It weren't us who made a decision about design goals, so the discussion on unintended consequences is under the feature request.
Extension persistently shows a type of expression on top of
https://marketplace.visualstudio.com/items?itemName=Orta.vscode-twoslash-queries
10x @dkzlv @khraks_mamtsov
// ?^
mark. It's indispensable for debugging of deeply nested type computations.https://marketplace.visualstudio.com/items?itemName=Orta.vscode-twoslash-queries
10x @dkzlv @khraks_mamtsov
No particularly life-changing features in this major version.
https://devblogs.microsoft.com/typescript/announcing-typescript-5-0/
https://devblogs.microsoft.com/typescript/announcing-typescript-5-0/
Microsoft News
Announcing TypeScript 5.0
Today we’re excited to announce the release of TypeScript 5.0! This release brings many new features, while aiming to make TypeScript smaller, simpler, and faster. We’ve implemented the new decorators standard, added functionality to better support ESM projects…
Here we gooo. Somebody started to work on an alternative standard library for TypeScript with sane types.
https://github.com/total-typescript/ts-reset
https://github.com/total-typescript/ts-reset
GitHub
GitHub - mattpocock/ts-reset: A 'CSS reset' for TypeScript, improving types for common JavaScript API's
A 'CSS reset' for TypeScript, improving types for common JavaScript API's - mattpocock/ts-reset