如何排除`tsconfig.js`目录中的任何文件?

时间:2019-05-07 02:45:30

标签: typescript

我在React项目中使用打字稿3.2.4。我在src/app/components/Demo/*.tsx中有一些演示代码,不想编译它们。如何将其从编译中排除?我已经尝试了tsconfig.jsin文件中的以下设置,但没有一个起作用。我仍然从src/app/components/Demo目录中看到很多编译错误

"exclude": ["build", "node_modules", "**/Demo/*"]
"exclude": ["build", "node_modules", "src/app/components/Demo/*"]
"exclude": ["build", "node_modules", "**/Demo"]
"exclude": ["build", "node_modules", "**/Demo/**/*"]
"exclude": ["build", "node_modules", "src/app/components/Demo/**/*.tsx"]
"exclude": ["build", "node_modules", "src/app/components/Demo/*.tsx"]

下面是编译错误,您会看到所有错误都在app/components/Demo/index.tsx文件中。

[tsl] ERROR in /Users/joeyzhao/dev/mpost/endstate/material-ui-es/src/app/components/Demo/index.tsx(401,16)
      TS2322: Type '{ children: (string | Element)[]; align: string; }' is not assignable to type 'DetailedHTMLProps<HTMLAttributes<HTMLParagraphElement>, HTMLParagraphElement>'.
  Property 'align' does not exist on type 'DetailedHTMLProps<HTMLAttributes<HTMLParagraphElement>, HTMLParagraphElement>'.

ERROR in /Users/joeyzhao/dev/mpost/endstate/material-ui-es/src/app/components/Demo/index.tsx
./app/components/Demo/index.tsx
[tsl] ERROR in /Users/joeyzhao/dev/mpost/endstate/material-ui-es/src/app/components/Demo/index.tsx(412,16)
      TS2322: Type '{ children: (string | Element)[]; align: string; }' is not assignable to type 'DetailedHTMLProps<HTMLAttributes<HTMLParagraphElement>, HTMLParagraphElement>'.
  Property 'align' does not exist on type 'DetailedHTMLProps<HTMLAttributes<HTMLParagraphElement>, HTMLParagraphElement>'.

ERROR in /Users/joeyzhao/dev/mpost/endstate/material-ui-es/src/app/components/Demo/index.tsx
./app/components/Demo/index.tsx
[tsl] ERROR in /Users/joeyzhao/dev/mpost/endstate/material-ui-es/src/app/components/Demo/index.tsx(516,20)
      TS2339: Property 'propTypes' does not exist on type 'typeof OutlinedTextFields'.

1 个答案:

答案 0 :(得分:0)

您可以使用2星标记来排除目录及其子目录中的所有文件:

"exclude": [
  "build",
  "node_modules",
  "src/app/components/Demo/**/*.tsx"
]

如果您只想排除目录中的直接子文件,只需加一个星号即可:

"exclude": [
  "build",
  "node_modules",
  "src/app/components/Demo/*.tsx"
]