Upgrading TypeScript to v4

Notes from upgrading to TypeScript 4.0—packages to bump, issues encountered, and fixes.

Oct 21, 2020 · 1 min read · 159 Words · -Views -Comments · Programming
TypeScript 🇨🇳 阅读中文版
Read with AI

Choose an AI assistant

ChatGPT Open in a new tab with the article link and prompt
Claude Copy the prompt, then open Claude

Open Claude
Trouble reading the article?

If the prompt is missing, copy the full prompt below into your AI assistant. If the AI cannot read the article, paste the visible passage you want to discuss and add your question.

I upgraded our project to TypeScript 4.0 to use newer TS/JS features like logical assignment operators. Here are the details.

Remember: TypeScript is about types—upgrading shouldn’t change runtime behavior.

Package Updates

{
  "typescript": "4.0.3",
  "@typescript-eslint/eslint-plugin": "^4.5.0",
  "@typescript-eslint/eslint-plugin-tslint": "^4.5.0",
  "@typescript-eslint/parser": "^4.5.0"
}
  • Upgrade related @typescript-eslint packages because ESLint relies on the TS parser.
  • Update other vendor types as needed when errors appear.

Issues Encountered

  1. Parsing error: Cannot read property 'map' of undefined — fixed by upgrading the @typescript-eslint packages above.

  2. Property 'canCostRelief' does not exist on type 'never' — TypeScript narrowed an intersection to never because selected had conflicting types (boolean vs string). Align the types.

  3. This expression is not callable — quoteLines was typed as A | B, but the helper expected A. Narrow it (quoteLines as A[]) or adjust the function signature.

Final Thoughts

Version upgrades can be bumpy, but they improve type safety and unlock language features. Treat issues as learning opportunities and don’t postpone upgrades indefinitely.

Authors
Developer, digital product enthusiast, tinkerer, sharer, open source lover