最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

typescript - Include ambient references for local files anywhere other than colocating them - Stack Overflow

programmeradmin3浏览0评论

I'm testing out how the TS compiler resolves ambient declarations for local files. I can't seem to find a way to tell it to look for type files if I put them anywhere other than right beside the source js files. Here's a demo. For example:

// src/templates/Hello.d.ts
declare function Hello(): string;
export default Hello;
// src/index.ts
import Hello from './templates/Hello.js'; // can't find declarations UNLESS Hello.d.ts is colocated.

Hello();
// tsconfig.json
{
  "compilerOptions": {
    "skipLibCheck": true,
    "noEmit": true
  },
  "include": ["src"]
}

What I'd like to do is to put the Hello.d.ts file in ./src/types/Hello.d.ts. I've tried various things like using baseUrl and paths in tsconfig.json, triple slash directives, using declare module (but I can't seem to use relative paths to point to the specific file I'm trying to create types for), but so far no luck.

发布评论

评论列表(0)

  1. 暂无评论