Skip to content

[Errors][Message] Module in type reference #102

Closed

Description

tests/cases/compiler/primaryExpressionMods.ts

module M
{
export interface P { x: number; y: number; }
export var a = 1;
}

var p: M.P; // Used as ModuleName

var m: M = M; // Used as TypeName and PrimaryExpression (error on TypeName)

var m2: typeof M = M; // Used as PrimaryExpression in TypeQuery

var x1 = M.a; // Used as PrimaryExpression

var x2 = m.a; // Same as M.a

var q: m.P; // Error

Old Compiler

Type reference cannot refer to container 'M'.

New Compiler

Cannot find name 'M'.

Activity

  1. added this to the milestone on Jul 17, 2014
  2. modified the milestones: , on Aug 29, 2014
  3. begincalendar commented on Oct 13, 2017

    @begincalendar
    Contributor

    I believe a solution might be:

    diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts
    index 9347329..20a57f0 100644
    --- a/src/compiler/checker.ts
    +++ b/src/compiler/checker.ts
    @@ -1366,7 +1366,7 @@ namespace ts {
                     }
                 }
                 else if (meaning & (SymbolFlags.Type & ~SymbolFlags.NamespaceModule & ~SymbolFlags.Value)) {
    -                const symbol = resolveSymbol(resolveName(errorLocation, name, SymbolFlags.NamespaceModule & ~SymbolFlags.Type, /*nameNotFoundMessage*/undefined, /*nameArg*/ undefined, /*isUse*/ false));
    +                const symbol = resolveSymbol(resolveName(errorLocation, name, (SymbolFlags.ValueModule | SymbolFlags.NamespaceModule) & ~SymbolFlags.Type, /*nameNotFoundMessage*/undefined, /*nameArg*/ undefined, /*isUse*/ false));
                     if (symbol) {
                         error(errorLocation, Diagnostics.Cannot_use_namespace_0_as_a_type, unescapeLeadingUnderscores(name));
                         return true;
    

    ...but it breaks a lot of other tests.

    I'm also thinking that the same logical OR should be used for the check to see whether a module is used as a value, but if that's the case then I wonder why SymbolFlags.ValueModule and SymbolFlags.NamespaceModule exist separately in the first place.

  4. modified the milestones: , TypeScript 2.7 on Oct 30, 2017
  5. added a commit that references this issue on Oct 30, 2017
    6de69df
  6. added
    Fixed
    on Oct 30, 2017
  7. mhegazy commented on Oct 30, 2017

    @mhegazy
    ContributorAuthor
  8. locked and limited conversation to collaborators on Jun 18, 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

    BugFixed

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions