Skip to content

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

Closed

Description

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

Activity

  1. changed the title [-]import member from export as namespace library[/-] [+]import member from export as namespace library does not import types[/+] on May 30, 2017
  2. cwmoo740 commented on May 30, 2017

    @cwmoo740
    Author

    The typing file for reselect may also be helpful:

    https://github.com/reactjs/reselect/blob/master/src/index.d.ts

  3. locked and limited conversation to collaborators on Jun 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

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