Skip to content

Node16 module resolution doesn't check side effect importsΒ #50394

Closed
@alecmev

Description

@alecmev

Bug Report

πŸ•— Version & Regression Information

This is the behavior in every version I tried, and I reviewed the FAQ for entries about this.

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

// @module: Node16
import "./file";

πŸ™ Actual behavior

TypeScript says nothing.

πŸ™‚ Expected behavior

I want TypeScript to tell me that .js is missing, the same way it does in any other type of import. I think I understand why it doesn't right now, because side effects have nothing to do with static analysis, so the incorrectness of the import doesn't prevent TypeScript from doing its job in any way, but:

  1. I haven't been able to set this up in the bug workbench, but what happens if the file is being imported from node_modules and has a corresponding .d.ts with a declare ... in it? Will that declare get applied?
  2. Wouldn't this be useful to have either way? I guess ESLint could fill this void, but seeing how eslint-plugin-import is dragging its feet on import/extensions, there's little hope for that.

Apologies if this has been addressed before, couldn't find.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Domain: Node ESMLike ES Modules, but specific to Node.js support (cts, cts, mjs, mts)In DiscussionNot yet reached consensusSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions