Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

export declared with export = DeviceDetector; forces me to use 'allowSyntheticDefaultImports' #148

Open
IARI opened this issue Aug 24, 2022 · 0 comments

Comments

@IARI
Copy link

IARI commented Aug 24, 2022

DeviceDetector is declared with export = DeviceDetector; and no default export is specified.

Our project was configured without 'allowSyntheticDefaultImports'.
With this configuration:

  1. an IDE like webstorm will automatically import DeviceDetector with the line
import * as React from "react";

which will work fine in development, but when the project is built, there will be exceptions, the DeviceDetector constructor will not be found.

Trying to import DeviceDetector with this configuration like this

import DeviceDetector from "device-detector-js";

leads to the following typescript error:

⚠️ Missing/incorrect detections should be reported at https://github.com/matomo-org/device-detector/issues instead of this repo.
TS1259: Module '"C:/dev/viuport/client/node_modules/device-detector-js/dist/index"' can only be default-imported using the 'allowSyntheticDefaultImports' flag index.d.ts(34, 1): This module is declared with using 'export =', and can only be used with a default import when using the 'allowSyntheticDefaultImports' flag.

see also https://www.typescriptlang.org/tsconfig#allowSyntheticDefaultImports

I would instead endorse exporting DeviceDetector as default, for example like this

export default class DeviceDetector {
// ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
@IARI and others