标签: tsconfig

在 TypeScript 的 tsconfig 文件中,如何排除“node_modules”文件夹但包含某些子文件

我有一个像这样的 tsconfig

{
  "compileOnSave": false,
  "compilerOptions": {
    "module": "es2015",
    "target": "es2015",
    "sourceMap": true,
    "jsx": "react",
    "allowSyntheticDefaultImports": true,
    "noImplicitAny": false,
    "watch": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "allowJs": true,
    "suppressOutputPathCheck": true
  },
  "exclude": [
    "dist",
    "node_modules",
    "bower_components",
    "typings/globals",
    "typings/modules"
  ]
}
Run Code Online (Sandbox Code Playgroud)

我正在使用 webpack 来捆绑我的项目文件。大多数定义文件都是使用类型添加的,但某些 npm 模块包含自己的定义文件。我希望能够将它们添加到打字稿编译中。否则我会得到类似的错误Cannot find module X

如何在编译中包含这些定义文件?

typescript tsconfig

2
推荐指数
1
解决办法
4913
查看次数

来自 FAL 的 Typo3 CKEditor 图像

我使用 CKEditor 设置了一个全新的 TYPO3 8.7.4 安装并rte_ckeditor_image从 FAL 获取图像。

rte_ckeditor_image它的文档中说:

最大尺寸与必须在 Page TSConfig 中设置的魔术图像的配置有关:

# Page TSConfig
RTE.default.buttons.image.options.magic {
    maxWidth = 1020  # Default: 300
    maxHeight = 800  # Default: 1000
}
Run Code Online (Sandbox Code Playgroud)

我这样做了,但仍然无法使图像的宽度大于 300 像素。

我已经看过TYPO3的源代码了。有一个文件typo3/sysext/core/Classes/Resource/Service/MagicImageService.php有两个变量:$magicImageMaximumWidth$magicImageMaximumHeight. 如果更改它们的值,我可以使图像的宽度大于 300 像素。

该文件还有一个函数setMagicImageMaximumDimensions(array $rteConfiguration),该函数应该更改两个变量,但似乎没有这样做。

我做错了什么还是无法更改最大图像尺寸?

谢谢。

typo3 ckeditor typoscript tsconfig fal

2
推荐指数
1
解决办法
771
查看次数

关于 angular4 项目中的 import {**} from @app/*

我在 Angular 项目中遇到了一个奇怪的现象。

\n\n

我的项目是从命令行自动生成的(ng new myproject)

\n\n

在项目中,目录\xef\xbc\x9a

\n\n
    \n
  • 应用程序\n\n
      \n
    • 共享\n\n
        \n
      • 常见\n\n
          \n
        • 应用程序组件库.ts
        • \n
      • \n
      • 会话\n\n
          \n
        • 应用程序会话.service
        • \n
      • \n
    • \n
  • \n
\n\n

应用程序组件基.ts

\n\n
import { AppSessionService } from \'@shared/session/app-session.service\';\n
Run Code Online (Sandbox Code Playgroud)\n\n

tsconfig.app.json:

\n\n
"paths": {\n    "@abp/*": [ "../node_modules/abp-ng2-module/src/*" ],\n    "@app/*": [ "./app/*" ],\n    "@shared/*": [ "./app/shared/*" ],\n    "@node_modules/*": [ "../node_modules/*" ]\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

vscode显示错误(不影响正常运行,但无法导航到该类)\xef\xbc\x9a

\n\n
[ts] Cannot find module \'@shared/session/app-session.service\'.\n
Run Code Online (Sandbox Code Playgroud)\n\n

我是否有任何配置错误?\n谢谢!

\n\n

我知道可能是这样,但我想使用通用符号\xef\xbc\x9a

\n\n
import { AppSessionService } from \'../session/app-session.service\';\n\n\n\n@angular/cli: …
Run Code Online (Sandbox Code Playgroud)

tsconfig angular

2
推荐指数
1
解决办法
5322
查看次数

打字稿错误 TS2531 对象可能为“null”,未被 strictNullChecks 抑制: false

我的打字稿编译抛出以下错误

TS2531:对象可能为“空”。

我正在转换带有大量此类错误的代码,只是想抑制它们以完成构建工作。据我了解,在 tsconfig.json 文件中添加以下内容可以抑制此错误。

“compilerOptions”:{“strictNullChecks”:false}

但是错误仍然显示。我找不到特定于此错误的任何其他编译器选项。有没有办法抑制它?

typescript tsconfig ts-loader

2
推荐指数
1
解决办法
3922
查看次数

架构验证失败并出现以下错误:数据路径“”应具有必需的属性“tsConfig”

最近我将我的角度应用程序移动到了一些不同的文件夹中。从那时起,当我想构建应用程序时,我收到此错误:

架构验证失败并出现以下错误:数据路径“”应具有必需的属性“tsConfig”

我尝试在 github 和 stackoverflow 中查找,只找到了这些链接:

https://github.com/angular/angular-cli/issues/11479

他们说我必须降级一个包:

“@Angular-devkit/build-Angular”:“^0.800.1”到“^0.12.4”

但这感觉不是正确的方式

{
  "name": "@xxx/ma",
  "version": "1.1.0",
  "private": true,
  "license": "UNLICENSED",
  "scripts": {
    "ng": "ng",
    "start": "ng serve --proxy-config proxy.conf.js",
    "build": "ng build --prod",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "doc": "compodoc -p src/tsconfig.app.json -s"
  },
  "dependencies": {
    "@angular/animations": "~8.2.1",
    "@angular/cdk": "~8.2.1",
    "@angular/common": "~8.2.1",
    "@angular/compiler": "~8.2.1",
    "@angular/core": "~8.2.1",
    "@angular/flex-layout": "8.0.0-beta.27",
    "@angular/forms": "~8.2.1",
    "@angular/material": "~8.2.1",
    "@angular/platform-browser": "~8.2.1",
    "@angular/platform-browser-dynamic": "~8.2.1",
    "@angular/platform-server": "~8.2.1",
    "@angular/pwa": "~0.802.1",
    "@angular/router": "~8.2.1",
    "@angular/service-worker": "~8.2.1",
    "@progress/kendo-angular-buttons": "~5.0.0", …
Run Code Online (Sandbox Code Playgroud)

tsconfig package.json angular

2
推荐指数
1
解决办法
2万
查看次数

错误 TS5023:未知的编译器选项“strictTemplates”

编译 Angular 应用程序 (v10) 失败并出现此错误。

An unhandled exception occurred: tsconfig.json:14:5 - error TS5023: Unknown compiler option 'strictTemplates'.

14     "strictTemplates": true,
       ~~~~~~~~~~~~~~~~~
Run Code Online (Sandbox Code Playgroud)

ivy typescript tsconfig angular

2
推荐指数
1
解决办法
736
查看次数

更新到 27 后,Angular jest 无法理解导入路径

这是一个奇怪的错误。所以我把 jest 更新到 27 然后全部停止工作

导入路径似乎有问题。所以下面的

import { something } form 'src/app/components/.....';
Run Code Online (Sandbox Code Playgroud)

不起作用,但这确实有效:

import { something } from '../../components/....';
Run Code Online (Sandbox Code Playgroud)

我猜这是在 tsconfig 中管理的。这是我的spectsconfig:

{
    "extends": "./tsconfig.json",
    "compilerOptions": {
    "outDir": "./out-tsc/spec",
    "types": [
        "jest", // 1
        "node",
        "Chrome"
    ],
    "esModuleInterop": true, // 2
    "emitDecoratorMetadata": true, // 3
    "allowSyntheticDefaultImports": true,
  },
  "files": ["src/test.ts", "src/polyfills.ts"],
  "include": ["src/**/*.spec.ts", "src/**/*.d.ts"]
}
Run Code Online (Sandbox Code Playgroud)

和主要的 tsconfig:

{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "downlevelIteration": true,
    "experimentalDecorators": true,
    "moduleResolution": "node",
    "importHelpers": true, …
Run Code Online (Sandbox Code Playgroud)

typescript tsconfig jestjs tsconfig-paths angular-jest

2
推荐指数
1
解决办法
883
查看次数

Eslint + typescript 路径别名 - 无法解析模块的路径

我为路径添加打字稿配置:

{
 //.....

 "moduleResolution": "node",
{
  "baseUrl": "app",
  "paths": {
  "@app/*": ["*"],
  "@folder/*": ["folder/*"],

  //Other paths
},
Run Code Online (Sandbox Code Playgroud)

}

为 webpack 添加配置:

  resolve: {
  extensions: [".tsx", ".ts", ".js", ".jsx", ".css", ".json"],
  alias: {
    "@app":path.resolve(__dirname + "../", "app"),
    "@services":path.resolve(__dirname + "../app", "folder")
  },
  modules: [
    "node_modules", path.resolve(process.cwd(), "app")
  ],
  plugins: [
    new TsConfigPathsPlugin({
      configFile: "../tsconfig.json"
    }),
  ],
},
Run Code Online (Sandbox Code Playgroud)

这是我的 .eslint 文件:

"settings": {
"import/resolver": {
  "node": {
    "paths": [
      "app"
    ],
    "extensions": [
      ".ts",
      ".tsx",
      ".jest.tsx",
      ".d.ts"
    ]
  }
}
Run Code Online (Sandbox Code Playgroud)

之后我尝试导入这样的东西:

import …
Run Code Online (Sandbox Code Playgroud)

reactjs eslint tsconfig react-tsx typescript-eslint

2
推荐指数
1
解决办法
1万
查看次数

在 tsconfig 文件中找不到“node_modules/typescript/lib/lib.d.ts”

在我更新软件包后,我看到了这个错误(同时我更新了我的 vs 代码)/我不知道如何修复这个错误,如果有人在这种情况下帮助我处理这个错误,我将不胜感激

  File 'c:/Program Files/Microsoft VS Code/resources/app/extensions/node_modules/typescript/lib/lib.d.ts' not found.
    The file is in the program because:
    Default library for target 'es5'
Run Code Online (Sandbox Code Playgroud)

tsconfig

2
推荐指数
1
解决办法
4617
查看次数

为什么 es2022 的 typescript 可选类属性设置为 undefined

Typescript 编译器对可选类属性的处理似乎已从 更改es2021es2022

class A {
    a?: string
    b?: string
    constructor() {
        this.b = 'asd'
    }
}
console.log(new A())
Run Code Online (Sandbox Code Playgroud)

与 tsconfig target=es2021结果

A: {
  "b": "asd"
} 
Run Code Online (Sandbox Code Playgroud)

与 tsconfig target=es2022结果

A: {
  "a": undefined,
  "b": "asd"
} 
Run Code Online (Sandbox Code Playgroud)

我找不到有关此更改的任何文档。这真的是有意的行为吗?为什么?

通过更改 TS Config->Target可以轻松在 ts Playground中重现

typescript tsc tsconfig es2022

2
推荐指数
1
解决办法
262
查看次数