首页 > 解决方案 > TypeScript: Exclude external types from the build output

问题描述

I'm creating a firebase functions with TypeScript and I have the following folder structure in the project:

- functions
--- src
------ auth.ts
- types
--- authResponse.ts

Inside my auth.ts file, I import the type from 'authResponse.ts`.

And as the result, when I build the code inside functions directory, I get the following output in the functions/lib directory:

-- lib
---- src
------- auth.js
---- types
------- authResponse.js

But I need the full output inside the lib directory like this:

-- lib
---- auth.js

I understand that it's caused by the fact that I'm importing types from the outside.

Is there any way to prevent it from appearing inside the lib folder? I've tried excluding it from tsconfig, but no luck.

标签: typescript

解决方案


根据您的问题,我假设您使用predeploy hook进行编译。

如果是,请重命名authResponse.tsauthResponse.d.ts. 代表定义,所以Typescriptd转译器会知道它不应该被转译。

查看本指南以编写定义文件


推荐阅读