我可以在 WebStorm/PhpStorm 中不使用 npm 或打字来安装 TypeScript 定义吗
Can I install TypeScript definitions without using npm or typings in WebStorm/PhpStorm
我刚刚发现我可以在此设置中安装 TypeScript 定义:
这很方便,因为我不需要使用 typings
或 npm
来安装类型。
但是 tsconfig.json
中的哪些设置使 WebStorm 使用这些定义? webstorm
下载的这些库真的有用吗?
我在 .tsx
中仍然得到 Cannot find module react
tsconfig.json:
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"moduleResolution": "node",
"removeComments": true,
"allowSyntheticDefaultImports": true,
"noImplicitAny": false,
"sourceMap": true,
"outDir": "./src/",
"jsx": "react",
"experimentalDecorators": true,
"noLib": false,
"declaration": false,
"emitDecoratorMetadata": true
},
"exclude": [
"node_modules",
"src"
]
}
package.json:
{
"name": "database",
"version": "0.0.1",
"private": true,
"dependencies": {
"axios": "^0.15.3",
"lodash": "^4.17.4",
"mobx": "^3.1.0",
"mobx-react": "^4.1.0",
"native-base": "^2.0.8",
"react": "15.4.2",
"react-native": "0.41.2",
"react-native-autocomplete-input": "^3.1.0",
"react-native-datepicker": "^1.4.4",
"react-native-extended-stylesheet": "^0.3.1",
"react-native-htmlview": "^0.5.0",
"react-native-mobx": "^0.3.1",
"react-native-modal-dropdown": "^0.4.1",
"react-native-orientation": "^1.17.0",
"react-native-pathjs-charts": "0.0.26",
"react-native-router-flux": "^3.37.0",
"react-native-sglistview": "^0.3.5",
"react-native-storage": "^0.1.5",
"react-native-view-shot": "^1.7.0",
"typescript": "^2.2.1"
},
"devDependencies": {
"babel-jest": "18.0.0",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-preset-react-native": "1.9.1",
"babel-preset-react-native-stage-0": "^1.0.1",
"jest": "18.1.0",
"react-test-renderer": "15.4.2"
},
"jest": {
"preset": "react-native"
}
}
你应该使用 npm,但如果你坚持不这样做,我建议创建一个 typings
目录,其中包含一个由模块名称组成的子目录,它本身包含定义文件
-typings
-react
react.d.ts
只需确保 typings 目录是编译路径的一部分,即不是 tsconfig.json
中的 excluded
在您的项目中使用它们的原因是这些文件包含版本化代码,就像您的其他打字稿文件一样
当您更改库版本时,很可能定义文件也需要更改以反映新的和已弃用的功能(并且您不希望 npm 为您管理它)
在 Javascript| Libraries
中配置的库仅供 PhpStorm 本身用于代码 completion/navigation,但它们不可用于 TypeScript 编译器服务。
当您通过 Settings | Languages & Frameworks | Javascript | Libraries
下载 Typescript 存根时,它们位于 ~/.PhpStorm*/config/javascript/extLibs/
中。这对 PhpStorm 来说非常好,但 tsc 编译器确实需要将 d.ts
文件放置在项目目录中的某个位置。
因此,要让下载的存根可用于 Typescript 编译器,您需要将它们 copy/move 到您的项目目录(并且可能重命名为更易读的名称 :))。届时它们将可用于 PhpStorm 和编译器。
我们计划在以后的版本中提供直接下载文件到项目文件夹的选项(而不是 system/extLibs/
),请关注 WEB-9237 for updates. Related feature request: WEB-14413
因此,如果您需要 TypeScript 编译器可以使用类型,那么使用 npm
(npm install @types/
) 似乎是最好的解决方案
我刚刚发现我可以在此设置中安装 TypeScript 定义:
这很方便,因为我不需要使用 typings
或 npm
来安装类型。
但是 tsconfig.json
中的哪些设置使 WebStorm 使用这些定义? webstorm
下载的这些库真的有用吗?
我在 .tsx
Cannot find module react
tsconfig.json:
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"moduleResolution": "node",
"removeComments": true,
"allowSyntheticDefaultImports": true,
"noImplicitAny": false,
"sourceMap": true,
"outDir": "./src/",
"jsx": "react",
"experimentalDecorators": true,
"noLib": false,
"declaration": false,
"emitDecoratorMetadata": true
},
"exclude": [
"node_modules",
"src"
]
}
package.json:
{
"name": "database",
"version": "0.0.1",
"private": true,
"dependencies": {
"axios": "^0.15.3",
"lodash": "^4.17.4",
"mobx": "^3.1.0",
"mobx-react": "^4.1.0",
"native-base": "^2.0.8",
"react": "15.4.2",
"react-native": "0.41.2",
"react-native-autocomplete-input": "^3.1.0",
"react-native-datepicker": "^1.4.4",
"react-native-extended-stylesheet": "^0.3.1",
"react-native-htmlview": "^0.5.0",
"react-native-mobx": "^0.3.1",
"react-native-modal-dropdown": "^0.4.1",
"react-native-orientation": "^1.17.0",
"react-native-pathjs-charts": "0.0.26",
"react-native-router-flux": "^3.37.0",
"react-native-sglistview": "^0.3.5",
"react-native-storage": "^0.1.5",
"react-native-view-shot": "^1.7.0",
"typescript": "^2.2.1"
},
"devDependencies": {
"babel-jest": "18.0.0",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-preset-react-native": "1.9.1",
"babel-preset-react-native-stage-0": "^1.0.1",
"jest": "18.1.0",
"react-test-renderer": "15.4.2"
},
"jest": {
"preset": "react-native"
}
}
你应该使用 npm,但如果你坚持不这样做,我建议创建一个 typings
目录,其中包含一个由模块名称组成的子目录,它本身包含定义文件
-typings
-react
react.d.ts
只需确保 typings 目录是编译路径的一部分,即不是 tsconfig.json
excluded
在您的项目中使用它们的原因是这些文件包含版本化代码,就像您的其他打字稿文件一样
当您更改库版本时,很可能定义文件也需要更改以反映新的和已弃用的功能(并且您不希望 npm 为您管理它)
在 Javascript| Libraries
中配置的库仅供 PhpStorm 本身用于代码 completion/navigation,但它们不可用于 TypeScript 编译器服务。
当您通过 Settings | Languages & Frameworks | Javascript | Libraries
下载 Typescript 存根时,它们位于 ~/.PhpStorm*/config/javascript/extLibs/
中。这对 PhpStorm 来说非常好,但 tsc 编译器确实需要将 d.ts
文件放置在项目目录中的某个位置。
因此,要让下载的存根可用于 Typescript 编译器,您需要将它们 copy/move 到您的项目目录(并且可能重命名为更易读的名称 :))。届时它们将可用于 PhpStorm 和编译器。
我们计划在以后的版本中提供直接下载文件到项目文件夹的选项(而不是 system/extLibs/
),请关注 WEB-9237 for updates. Related feature request: WEB-14413
因此,如果您需要 TypeScript 编译器可以使用类型,那么使用 npm
(npm install @types/
) 似乎是最好的解决方案