chalk/strip-ansi

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

starpit posted onGitHub

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'

The TypeScript team does not like us faking ES6 exports: https://github.com/sindresorhus/mem/issues/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.

posted by sindresorhus over 5 years ago

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

posted by starpit over 5 years ago

Fund this Issue

$0.00
Funded

Pull requests