Microsoft/TypeScript

Imports in .d.ts files break wildcard modules declarations

Open

#28,097 创建于 2018年10月24日

在 GitHub 查看
 (13 评论) (16 反应) (0 负责人)TypeScript (48,455 star) (6,726 fork)batch import
BugDomain: Related Error SpansHelp Wanted

描述

TypeScript Version: 3.1.3

Search Terms:

import d.ts wildcard module

Code

main.ts

/// <reference path="./typings.d.ts" />

import template from './template.html';

typings.d.ts

import * as _angular from 'angular';

declare module '*.html' {
  const content : string;
  export default content;
}
{
  "name": "ts-bug",
  "version": "1.0.0",
  "dependencies": {
    "angular": "^1.7.5"
  }
}

Compile with:

tsc main.ts

Expected behavior:

Compiled without errors.

Actual behavior: Compiled with error

main.ts:3:22 - error TS2307: Cannot find module './template.html'.

3 import template from './template.html';
                       ~~~~~~~~~~~~~~~~~

Removing import * as _angular from 'angular'; fixes the issue.

Side Note 1

Regular module declarations work regardless of imports being present.

Side Note 2 import * as _angular from 'angular'; is needed to later do:

declare global {
  const angular : typeof _angular;
}

to workaround https://github.com/Microsoft/TypeScript/issues/10178

贡献者指南