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

suggestion: offer a "default" export option to increase compatibility with es6 #31

Closed
starpit opened this issue Dec 6, 2019 · 2 comments

Comments

@starpit
Copy link

starpit commented Dec 6, 2019

when coding in typescript, using an es6 or exnext module backend, the suggested

import stripAnsi = require('strip-ansi')

is not allowed

error TS1202: Import assignment cannot be used when targeting ECMAScript modules

an option, in these cases, is to use instead

import * as stripAnsi from 'strip-ansi'

but this requires that one's entire project be compiled with allowSyntheticDefaultImports, which has fairly wide-ranging implications on the code base, especially with regards to dynamic imports.

might i suggest that strip-ansi offer e.g. an es6.js whose content is something like:

https://github.com/starpit/strip-ansi/blob/es6/es6.js
https://github.com/starpit/strip-ansi/blob/es6/es6.d.ts

which would allow

import stripAnsi from 'strip-ansi/es6'
starpit added a commit to starpit/strip-ansi that referenced this issue Dec 6, 2019
starpit added a commit to starpit/strip-ansi that referenced this issue Dec 6, 2019
@sindresorhus
Copy link
Member

The TypeScript team does not like us faking ES6 exports: sindresorhus/memoize#31


but this requires that one's entire project be compiled with allowSyntheticDefaultImports, which has fairly wide-ranging implications on the code base, especially with regards to dynamic imports.

Sounds like you need to open a TypeScript issue instead about this.


I'm going to pass on this as this is a slippery slope. If I allow this, I'll get requests for a separate ES6 sub-export for many of my other packages, and i'm just not interested in adding lots of temporary bloat and spending time on this because of TypeScript limitations.

This is a temporary problem anyway. We're getting very close to have import/export natively in Node.js, and then I'll just fully switch over.

@starpit
Copy link
Author

starpit commented Dec 6, 2019

ok, we'll fork for now until typescript and es6 converge. thanks for the consideration.

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

Successfully merging a pull request may close this issue.

2 participants