Skip to content

Suggestion: compiler option to validate "empty imports" #28411

Description

Search Terms

empy import cannot find module symbols side deffect

Suggestion

Current behaviour: given an empty import (an import that has side effects and/or does not import any symbols):

import './abc';

If the module does not exist, there will be no error.

This is unlike other (non-empty) imports, which will error for non-existent modules:

import 'foo' from ./abc';

I understand this is intended behaviour as per #20534 (comment).

I would like to suggest a compiler option for people to opt-in to the stricter behaviour. This could also be added to the strict compiler option.

Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript / JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. new expression-level syntax)

Metadata

Metadata

Assignees

No one assigned

    Labels

    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