Skip to content

Keyof module import does not have 'default' as an option #28706

@MLoughry

Description

@MLoughry

TypeScript Version: 3.3.0-dev.20181128, 3.2.0-rc (does not repro in 3.1.6)

Search Terms:
keyof module, default, spyOn, jest

Code

// example.ts
export default function add(a: number, b: number) {
    return a + b;
}

//exampleTest.ts
import * as example from '../example';

describe('add', () => {
    it('does something', () => {
        spyOn(example, 'default');
    })
})

Uses @types/jest@23.3.9, with the following declaration:

declare function spyOn<T>(object: T, method: keyof T): jasmine.Spy;

Expected behavior:
spyOn(example, 'default') throws no errors, as the only export from the example.ts module is a default export.

Actual behavior:

src/__tests__/exampleTest.ts:5:24 - error TS2345: Argument of type '"default"' is not assignable to parameter of type '"add"'.

Playground Link: None; the playground doesn't seem to support multiple modules

Related Issues: None that I could find.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptDomain: ES ModulesThe issue relates to import/export style module behaviorHigh Priority

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions