Skip to content

Losing types when importing cjs module using default export with nodenext modules #48845

Closed as not planned
@wight554

Description

@wight554

Bug Report

🔎 Search Terms

cjs typescript nodenext default export

🕗 Version & Regression Information

4.7.0-dev

While using nodenext with pure cjs modules, such as https://github.com/fastify/fastify-cookie or https://github.com/fastify/fastify-static , types are lost when using default export and cjs named export is prohibited

⏯ Playground Link

Playground link with relevant code

💻 Code

import fastifyCookie from 'fastify-cookie';
import fastifyStatic from 'fastify-static';

app.register(fastifyCookie);
app.register(fastifyStatic);

🙁 Actual behavior

import fastifyCookie
Argument of type 'typeof import("/.../node_modules/fastify-cookie/plugin")' is not assignable to parameter of type 'FastifyPluginCallback<any, Server> | FastifyPluginAsync<any, Server> | Promise<{ default: FastifyPluginCallback<any, Server>; }> | Promise<...>'.ts(2345)

🙂 Expected behavior

Type should not be lost while import
Can be workaround by

import { default as fastifyCookie } from 'fastify-cookie';
import { default as fastifyStatic } from 'fastify-static';

But i'm not sure if that's expected or not

Metadata

Metadata

Assignees

No one assigned

    Labels

    ExternalRelates to another program, environment, or user action which we cannot control.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions