Skip to content
This repository was archived by the owner on May 22, 2025. It is now read-only.
This repository was archived by the owner on May 22, 2025. It is now read-only.

Unexpected behavior when transpiling console interface from @types/node #301

@traviskaufman

Description

@traviskaufman

tsickle version: 0.2.2
typescript version: 2.1.4

Given this tsconfig.json:

{
  "files": ["index.d.ts"]
}

And this slimmed down example of @types/node's index.d.ts:

interface Console {
  Console: typeof NodeJS.Console;
}

declare namespace NodeJS {
  export var Console: {
    prototype: Console;
  }
}

Running tsickle --externs=externs.js produces the following output for me in externs.js:

/**
 * @externs
 * @suppress {duplicate}
 */
// NOTE: generated by tsickle, do not edit.
 /** @type {?} */
Console.prototype.Console;
/** @const */
var NodeJS = {};
 /** @type {?} */
NodeJS.Console;

Notice how the initial Console statement is omitted.


However, if I simply change the interface names in index.d.ts:

interface Foo {
  Foo: typeof NodeJS.Foo;
}

declare namespace NodeJS {
  export var Foo: {
    prototype: Foo;
  }
}

Running the same command gives me the following externs.js:

/**
 * @externs
 * @suppress {duplicate}
 */
// NOTE: generated by tsickle, do not edit.

/** @record @struct */
function Foo() {}
 /** @type {?} */
Foo.prototype.Foo;
/** @const */
var NodeJS = {};
 /** @type {?} */
NodeJS.Foo;

Notice how the initial function Foo() statement is not omitted.


The full reference file can be found at https://github.com/DefinitelyTyped/DefinitelyTyped/blob/types-2.0/node/index.d.ts. Looks like this also happens for builtins like ErrorConstructor. Could this be because we're assuming that closure is operating with --env BROWSER and therefore we don't want to overwrite these globals?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions