Skip to content

Import wrongly elided with a combination of default export, named export, non-exported type Β #47598

@Retsam

Description

@Retsam

Bug Report

πŸ”Ž Search Terms

import, elision, elided, default

πŸ•— Version & Regression Information

  • This changed between versions 4.1.5 and 4.2.3

⏯ Playground Link

Workbench Repro

πŸ’» Code

// @showEmit
import MyFunction from "./MyComponent";

MyFunction({msg: "Hello World"}); // Runtime error, MyFunction was not imported


// @filename: MyComponent.ts
interface MyFunction { msg: string; } // adding export here fixes

export const MyFunction = ({ msg }: MyFunction) => console.log(`Got message "${msg}"`); // removing export here fixes
export default MyFunction;

πŸ™ Actual behavior

The import MyFunction from "./MyComponent"; is elided from the output - causing the MyFunction(x) line to crash.

πŸ™‚ Expected behavior

Expected the import not to be elided since it is exporting a value, and the import is used as a value.

Alternatively, an error about this pattern of default export + named export + non-exported type would be helpful. This is a bizarre, accidental, export pattern, and it was an easy fix, but it was a bit tricky to track down. (We found this when switching a large codebase from babel compilation to TS compilation)

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issueRescheduledThis issue was previously scheduled to an earlier milestone

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions