Skip to content

Difference between import * and import {} with augmented module #12030

Closed

Description

TypeScript Version: nightly (2.1.0-dev.20161103)

Code

(Put in test/cases/compiler/importVsImport.ts and run tests)

// @Filename: /types/lib/index.d.ts
declare var lib: lib.Static;
export as namespace lib;
export = lib;

declare namespace lib {
    interface Static {
        stat(): void;
    }
}

// @Filename: /types/lib-extender/index.d.ts
import * as lib from "lib";

declare module "lib" {
    export function fn(): void;
}

// @Filename: /src/a.ts
import * as lib from "lib";
lib.fn();

import { fn } from "lib";
fn();

// @Filename: /tsconfig.json
{
    "compilerOptions": {
        "baseUrl": ".",
        "paths": {
            "*": ["types/*"]
        }
    }
}

Expected behavior:

No error.

Actual behavior:

/src/a.ts(2,5): error TS2339: Property 'fn' does not exist on type 'Static'.

This is based on angular-ui-router-default-tests.ts in DefinitelyTyped, which currently does not work. angular-ui-router augments the angular module, which also has a export =.

Activity

  1. added this to the milestone on Nov 3, 2016
  2. aluanhaddad commented on Nov 3, 2016

    @aluanhaddad
    Contributor

    This isn't actually a default export right? My understanding of UMD declarations is that export = still has commonjs implications. Is that correct?

  3. aluanhaddad commented on Nov 4, 2016

    @aluanhaddad
    Contributor

    Andy (Andrewkraft) (@Andy-MS) Thank you.

    I was tripped up by the statement

    This is based on angular-ui-router-default-tests.ts in DefinitelyTyped, which currently does not work. angular-ui-router augments the angular module, which also has a default export.

    because it does not have a default export, but rather exports all meanings of angular as the exports object.

  4. modified the milestones: TypeScript 2.2, on Nov 18, 2016
  5. ghost closed this as completedin #12672on Jan 25, 2017
  6. locked and limited conversation to collaborators on Jun 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptFixedA PR has been merged for this issue

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions