Skip to content

TS incorrectly flags a side effect-only import as TS5097 (An import path can only end with a '.ts' extension...) in --watch modeΒ #58791

@Aarononomous

Description

@Aarononomous

πŸ”Ž Search Terms

"TS5097", "allowImportingTsExtensions", "noEmit", "watch", "side effect", "import"

πŸ•— Version & Regression Information

  • This changed in commit or PR 89e928e

⏯ Playground Link

No response

πŸ’» Code

When importing a .ts file strictly for side effects,

import './a.ts';

I expect that this will be accepted by the typechecker. In fact, even if a.ts didn't exist, this would still be valid TS, see #50394 (comment) for a motivating example.

Typechecking with --noEmit validates this without error.

Typechecking with --watch gives me error TS5097: An import path can only end with a '.ts' extension when 'allowImportingTsExtensions' is enabled.

a.ts

console.log("I'm a side effect!");

b.ts

import './a.ts';

tsconfig.json

{}

πŸ™ Actual behavior

% npx tsc --noEmit # no output. Valid!
% npx tsc --watch
[5:54:03 PM] Starting compilation in watch mode...

b.ts:1:8 - error TS5097: An import path can only end with a '.ts' extension when 'allowImportingTsExtensions' is enabled.

1 import './a.ts';
         ~~~~~~~~

[5:54:04 PM] Found 1 error. Watching for file changes.

I shouldn't see a new error only in --watch mode.

πŸ™‚ Expected behavior

% npx tsc --noEmit # no output. Valid.
% npx tsc --watch
[5:54:37 PM] File change detected. Starting incremental compilation...

[5:54:37 PM] Found 0 errors. Watching for file changes.

Additional information about the issue

Workaround: // @ts-ignore before the import.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Fix AvailableA PR has been opened for this issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions