Skip to content

Exception, when attempting to add declaration to prototype namespace #18356

Description

@devoto13

TypeScript Version: 2.5.2 and 2.6.0-dev.20170909

Code

Background: I was trying to find a way to add a member to a class exported using export = ClassName; (which is not the point of this issue) and spotted a compiler crash with below code (which is the point of this issue).

// types.d.ts
declare module "foo" {
  class Foo {
    static a(): void;

    a(): void;
  }
  namespace Foo {}

  export = Foo;
}

// main.ts

declare module "foo" {
  function test(): void;
  namespace prototype {
    function test(): void;
  }
}

import Foo = require('foo');

const m = new Foo();
m.test();
Foo.test();

Expected behavior:

Some error is reported.

Actual behavior:

It throws:

/Users/devoto13/Projects/ts-augment/node_modules/typescript/lib/tsc.js:18935
            result.declarations = symbol.declarations.slice(0);
                                                     ^

TypeError: Cannot read property 'slice' of undefined
    at cloneSymbol (/Users/devoto13/Projects/ts-augment/node_modules/typescript/lib/tsc.js:18935:54)
    at /Users/devoto13/Projects/ts-augment/node_modules/typescript/lib/tsc.js:18994:40
    at Map.forEach (native)
    at mergeSymbolTable (/Users/devoto13/Projects/ts-augment/node_modules/typescript/lib/tsc.js:18987:20)
    at mergeSymbol (/Users/devoto13/Projects/ts-augment/node_modules/typescript/lib/tsc.js:18968:21)
    at mergeModuleAugmentation (/Users/devoto13/Projects/ts-augment/node_modules/typescript/lib/tsc.js:19021:21)
    at initializeTypeChecker (/Users/devoto13/Projects/ts-augment/node_modules/typescript/lib/tsc.js:36847:25)
    at Object.createTypeChecker (/Users/devoto13/Projects/ts-augment/node_modules/typescript/lib/tsc.js:18854:9)
    at getDiagnosticsProducingTypeChecker (/Users/devoto13/Projects/ts-augment/node_modules/typescript/lib/tsc.js:56392:93)
    at Object.getGlobalDiagnostics (/Users/devoto13/Projects/ts-augment/node_modules/typescript/lib/tsc.js:56720:53)
    at compileProgram (/Users/devoto13/Projects/ts-augment/node_modules/typescript/lib/tsc.js:59465:78)
    at compile (/Users/devoto13/Projects/ts-augment/node_modules/typescript/lib/tsc.js:59424:26)
    at performCompilation (/Users/devoto13/Projects/ts-augment/node_modules/typescript/lib/tsc.js:59313:33)
    at Object.executeCommandLine (/Users/devoto13/Projects/ts-augment/node_modules/typescript/lib/tsc.js:59256:9)
    at Object.<anonymous> (/Users/devoto13/Projects/ts-augment/node_modules/typescript/lib/tsc.js:59614:4)
    at Module._compile (module.js:573:30)
    at Object.Module._extensions..js (module.js:584:10)
    at Module.load (module.js:507:32)
    at tryModuleLoad (module.js:470:12)
    at Function.Module._load (module.js:462:3)
    at Module.require (module.js:517:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/Users/devoto13/Projects/ts-augment/node_modules/typescript/bin/tsc:2:1)
    at Module._compile (module.js:573:30)
    at Object.Module._extensions..js (module.js:584:10)
    at Module.load (module.js:507:32)
    at tryModuleLoad (module.js:470:12)
    at Function.Module._load (module.js:462:3)
    at Function.Module.runMain (module.js:609:10)
    at startup (bootstrap_node.js:158:16)
    at bootstrap_node.js:598:3

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptFixedA PR has been merged for this issue

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions