Blueprint: TypeScript won't compile with allowSyntheticDefaultImports disabled

Created on 5 Mar 2021  路  3Comments  路  Source: palantir/blueprint

Environment

  • __Package version(s)__:
    // Picked possibly relevant packages "devDependencies": { "@types/react": "^17.0.2", "@types/react-dom": "^17.0.1", "@types/styled-components": "^5.1.7", "typescript": "^4.2.3", }, "dependencies": { "@blueprintjs/core": "^3.40.0", "@blueprintjs/icons": "^3.25.0", "react": "^17.0.1", "react-dom": "^17.0.1", },
  • __Operating System__: Linux
  • __Browser name and version__: Firefox 87

Code Sandbox

Link to a minimal repro (fork this code sandbox): https://codesandbox.io/s/blueprintjs-ts-error-7nfml?file=/src/enabled/tsconfig.json

The sandbox is created using a Vanilla TypeScript template instead of the prepped one. I couldn't reproduce it on the template. Probably CRA-ts or other packages affect tsconfig.json (or not?) 馃

tsconfig.json on the sandbox is copied from the BluePrint Sandbox and both enabled/index.tsx and disabled/index.tsx are copied from src/Navigation.tsx.

Steps to reproduce

  1. Install @blueprintjs/core on a TS project without allowSyntheticDefaultImports: true
  2. Use imported components in JSX
  3. tsc --noEmit or Open IDE with TS support

Actual behavior

TypeScript compiler emits compile errors such as:

'AnchorButton' cannot be used as a JSX component.
  Its instance type 'AnchorButton' is not a valid JSX element.
    Type 'AnchorButton' is missing the following properties from type 'ElementClass': context, setState, forceUpdate, props, refsts(2786)

Expected behavior

Compiles without any error.

Possible solution

It seems that the library uses import React from "react" and they are the root cause of the error. Replacing from that to import * as React from "react" would solve the problem.

Current workaround is to enable allowSyntheticDefaultImports on user-side.

tooling P1

Most helpful comment

Sorry this got introduced as a break without a major version bump... I suppose it could have waited until the upcoming 4.0 release. I am inclined to move in this direction since most React code examples are written in the Babel style which has synthetic default imports. But it's not good to force a build system change in a minor version like this. I'll revert and push a patch release.

All 3 comments

Sorry this got introduced as a break without a major version bump... I suppose it could have waited until the upcoming 4.0 release. I am inclined to move in this direction since most React code examples are written in the Babel style which has synthetic default imports. But it's not good to force a build system change in a minor version like this. I'll revert and push a patch release.

Fixed by f515648bc0c5dd95de282b8d2332829263735bfb

Not fixed, actually

Was this page helpful?
0 / 5 - 0 ratings

Related issues

anasbud picture anasbud  路  20Comments

ripitrust picture ripitrust  路  19Comments

mulholio picture mulholio  路  20Comments

NickyYo picture NickyYo  路  18Comments

isTravis picture isTravis  路  43Comments