How to fix “Expression produces a union type that is too complex to represent. ts(2590)”?

VSCode Typescript Extension

Make sure you are using the right typescript version.
Typescript extension can use its own version instead of using your project’s typescript version which is set in package.json

  1. Open a JavaScript or TypeScript file in VS Code.
  2. In the VS Code command palette (F1 is the shortcut by default), run the TypeScript: Select TypeScript version command.
  3. Make sure you have Use workspace version selected

If there is no Use workspace version option
Make sure you have typescript in your dependencies in package.json and you have installed your dependencies by using npm install or npm clean-install
If you still do not have it – add typescript.enablePromptUseWorkspaceTsdk: true to .vscode/settings.json or find setting Enable Prompt Use Workspace Tsdk and enable it

Recomendation

Setup typescript extension to prompt you whether to use workspace version
Find setting ‘Typescript: Enable Prompt Use Workspace Tsdk’ in VsCode settings and enable it
enter image description here
In the next time you open your workspace in VsCode you will see this notification:
enter image description here
You want to click “Allow” 🙂

Other Possible Solutions

  1. Update npm version
    If you use nvm – nvm install --latest-npm
  2. Update nodejs version
    If you are unable to update nodejs at the moment to the latest version you can update it to atlest the latest minor+path version (x.latest.latest) to not have breaking changes
  3. Remove node_modules and npm install
  4. if you have project separated by folders and it is situated inside of those, you are unable to select typescript version in vscode. In that case open new vscode and go directly into your folder with package.json. (https://stackoverflow.com/users/5246617/pavol-travnik)

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)