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

TypeScript 4.5.0 has issues with our MJS #1597

Closed
FossPrime opened this issue Oct 8, 2021 · 2 comments
Closed

TypeScript 4.5.0 has issues with our MJS #1597

FossPrime opened this issue Oct 8, 2021 · 2 comments

Comments

@FossPrime
Copy link

FossPrime commented Oct 8, 2021

Related to #1513

When using Node in ESM mode and TypeScript 4.5 with compilerOptions.module set to "node12" OR "nodenext" ESModuleInteropt is no longer needed and the MJS export can be used directly with TypeScript.

The problem comes when we use @types/koa... which doesn't define a default type export! Therefore Koa effectively has no types in this situation.

Solution #1

Make a named export called Application in the MJS wrapper.

Solution #2

Add types to the MJS export with dist/koa.d.ts that references the DefinitelyTyped Koa definitions

// dist/koa.d.ts
import { Application } from "@types/koa"
declare module "koa" {
  export const mod: Application
}

Solution #3

Rename mod to Application in dist/koa.mjs... then export Application as default

Details

@FossPrime FossPrime changed the title TypeScript 4.5.0 has issues with @types/koa TypeScript 4.5.0 has issues with our MJS Oct 8, 2021
@killagu
Copy link

killagu commented Nov 16, 2021

@rayfoss With this solutions, Should we use like import { Application} from 'koa'?

@FossPrime
Copy link
Author

FossPrime commented Nov 16, 2021

Lots of changes happened to ts-node, typescript... and even Node LTS. I can no longer reproduce.

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