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

PR: TypeScript has no .mjs .cjs support out of the box #379

Open
frank-dspeed opened this issue Sep 3, 2020 · 3 comments
Open

PR: TypeScript has no .mjs .cjs support out of the box #379

frank-dspeed opened this issue Sep 3, 2020 · 3 comments

Comments

@frank-dspeed
Copy link

frank-dspeed commented Sep 3, 2020

TypeScript has no .mjs .cjs support out of the box i have a patched version of it but it is a blocking issue since 5+ years and will not get solved soon

to be compatible with ECMAScript modules we need to release a diffrent version of @vertx/* we need to release a CJS and a ESM version both with the same .d.ts files and the extension needs to be .js even for the ECMAScript version. So that there is intelliSense support inside the IDE.

also files like mod.mjs need to be converted to Module style so no extension defined else it will not find the .d.ts files

the current version of @vertx/* only works with require when the module specifier is used and with .mjs we get no types.

Update

We should offer the following formart

Method 1

SubFolder esm needs to contain package,json which references the type and types

// @vertx/**/esm/*.js,*.d.ts // The d.ts should import and reexport @vertx/**/*.d.ts

// Allows import like
import '@vertx/core/esm'
require('@vertx/core/cjs'

Method 2

// @vertx/**/*.mjs.d.ts // The d.ts should import and reexport @vertx/**/*.d.ts

// Allows import like
import '@vertx/core/index.mjs'
require('@vertx/core')

Method 3 most best at present!

Combine 1 and 2
till typescript adopts .mjs .cjs support

at present it is not possible to use vertx inside the ESM context with correct types inside the IDE

Reproduce

import { FileSystem } from '@vertx/core'
// Will throw as it loads the CJS version.
// import { FileSystem } from '@vertx/core/index.mjs' would not throw but would have no types added we would need to add index.mjs.d.ts which needs to reexport the content of index.d.ts
es4x init
npm install @vertx/core
# Create index.mjs
es4x install
es4x index.mjs
@frank-dspeed
Copy link
Author

Will create a PR i have added it to the generators so that method 2 works as this is the less inversive methode

@frank-dspeed frank-dspeed changed the title TypeScript has no .mjs .cjs support out of the box PR: TypeScript has no .mjs .cjs support out of the box Sep 3, 2020
@frank-dspeed
Copy link
Author

this needs also clean up inside Documentation https://github.com/reactiverse/es4x/blob/develop/docs/get-started/hello-world.md

first line should be to
/// to get typings?
// @ts-check

to turn on allowJs or create a jsconfig.json with {} as content

we should list all 3 methods

@lemanschik
Copy link

typescript now got mjs support by the way this needs to get closed @pmlopes

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