Skip to content

Triple-slash references duplicated in .d.ts with printer.printFile #36242

Closed
@sandersn

Description

@sandersn

Compare https://github.com/sandersn/downlevel-dts/blob/0eb977fcbdbd16f5e738a046c8c3d9c59537b5dd/test/test.d.ts#L1 to
https://github.com/sandersn/downlevel-dts/blob/0eb977fcbdbd16f5e738a046c8c3d9c59537b5dd/baselines/ts3.4/test.d.ts#L1

The code that produces this erroneous output is pretty simple:

https://github.com/sandersn/downlevel-dts/blob/0eb977fcbdbd16f5e738a046c8c3d9c59537b5dd/index.js#L132

Here's a simplified version:

  const program = ts.createProgram(['./test.d.ts'], {});
  const files = program.getRootFileNames().map(program.getSourceFile);
  const printer = ts.createPrinter({
    newLine: ts.NewLineKind.CarriageReturnLineFeed
  });
  for (const f of files) {
    console.log(printer.printFile(f));
  }

Create test.d.ts with the following text:

/// <reference types="node" />
/// <reference path="./src/test.d.ts" />

I also tested with multiple triple-slash references; in that case, all references are duplicated.

Metadata

Metadata

Assignees

Labels

Fix AvailableA PR has been opened for this issueNeeds InvestigationThis issue needs a team member to investigate its status.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions