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

[unsure] Adjust how sanitize is made available for Typescript? #73

Open
kberg opened this issue Nov 19, 2022 · 2 comments
Open

[unsure] Adjust how sanitize is made available for Typescript? #73

kberg opened this issue Nov 19, 2022 · 2 comments

Comments

@kberg
Copy link

kberg commented Nov 19, 2022

AFAICT, the way which sanitize is exported isn't ideal:

https://github.com/parshap/node-sanitize-filename/blob/master/index.d.ts#L8

export = sanitize;

When I try to reference it using a standard Typescript import statement,

image

I get these two errors:

'sanitize' can only be imported by using 'import sanitize = require(\"sanitize-filename\")' or by turning on the 'esModuleInterop' flag and using a default import.
`This module can only be referenced with ECMAScript imports/exports by turning on the 'esModuleInterop' flag and referencing its default export.

As far as I can tell, this might be resolved changing export=sanitize to export sanitize.

ref: https://stackoverflow.com/questions/68785926/this-module-can-only-be-referenced-with-ecmascript-imports-exports-by-turning-on

@DanielBlytheCTO
Copy link

I have the same problem. Did you manage to solve this?

@christurnbull
Copy link

npm i -D @types/sanitize-filename

I found that VS Code auto inserts this, which references the types:

import sanitize = require("sanitize-filename")

and use:

const str = sanitize("abc/def.txt")

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

3 participants