Skip to content

import member from export as namespace library does not import types #16155

Closed
@cwmoo740

Description

@cwmoo740

TypeScript Version: 2.3.3

Code

import { createSelector } from 'reselect';
/*
 * changing the import to
 * import * as reselect from 'reselect';
 * and accessing reselect.createSelector fixes the issue
*/
export interface State {
    a: string;
    b: number;
}
export const selector = createSelector<State, string, number, { out: string }>(
    state => state.a,
    state => state.b,
    (a, b) => {
        return {
            out: `${a}+${b}`
        };
    }
);
console.log(selector({ a: 'string', b: 5 }));

outputs this index.d.ts:

export interface State {
    a: string;
    b: number;
}
export declare const selector: Reselect.OutputSelector<State, {
    out: string;
}, (res1: string, res2: number) => {
    out: string;
}>;

Expected behavior:
The output .d.ts file will include an import for the relevant type from 'reselect'.

Actual behavior:
The output .d.ts file attempts to access Reselect as a global namespace. Any downstream consumer that imports from this code will error.

A full example can be found here:

https://github.com/cwmoo740/typescript-export-as-bug

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptDomain: Declaration EmitThe issue relates to the emission of d.ts filesFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions