Skip to content

ESM X.test which have zero export statement, should be sub type of ESM X which have at least one export statement#57735

@loynoir

Description

@loynoir

🔎 Search Terms

  • dynamic import

  • type union

  • no export

  • export{}

  • export default{}

🕗 Version & Regression Information

⏯ Playground Link

No response

💻 Code

reproduce.ts

asyncfunctionoptionalImport(id: string){switch(id){case'a': returnawaitimport('./a.js')case'a.test': returnawaitimport('./a.test.js')}thrownewError()}export{optionalImport}

a.ts

exportconstfoo=42

🙁 Actual behavior

  • When a.test.ts
import{foo}from'./a.js'describe('reproduce',()=>{it('reproduce',()=>{foo})})

type is

functionoptionalImport(id: string): Promise<typeofimport("/path/to/reproduce/a.test")>
  • When a.test.ts
import{foo}from'./a.js'describe('reproduce',()=>{it('reproduce',()=>{foo})})export{}

type is

functionoptionalImport(id: string): Promise<typeofimport("/path/to/reproduce/a.test")>
  • When a.test.ts
import{foo}from'./a.js'describe('reproduce',()=>{it('reproduce',()=>{foo})})exportdefault{}

type is

functionoptionalImport(id: string): Promise<typeofimport("/path/to/reproduce/a")|typeofimport("/path/to/reproduce/a.test")>

🙂 Expected behavior

When a.test.ts

import{foo}from'./a.js'describe('reproduce',()=>{it('reproduce',()=>{foo})})

type is

functionoptionalImport(id: string): Promise<typeofimport("/path/to/reproduce/a")|typeofimport("/path/to/reproduce/a.test")>

Additional information about the issue

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Not a DefectThis behavior is one of several equally-correct options

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions