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

Closed as not planned
@loynoir

Description

@loynoir

πŸ”Ž Search Terms

  • dynamic import

  • type union

  • no export

  • export {}

  • export default {}

πŸ•— Version & Regression Information

⏯ Playground Link

No response

πŸ’» Code

reproduce.ts

async function optionalImport(id: string) {
  switch (id) {
    case 'a':
      return await import('./a.js')
    case 'a.test':
      return await import('./a.test.js')
  }

  throw new Error()
}

export { optionalImport }

a.ts

export const foo = 42

πŸ™ Actual behavior

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

type is

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

type is

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

type is

function optionalImport(id: string): Promise<typeof import("/path/to/reproduce/a") | typeof import("/path/to/reproduce/a.test")>

πŸ™‚ Expected behavior

When a.test.ts

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

type is

function optionalImport(id: string): Promise<typeof import("/path/to/reproduce/a") | typeof import("/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