2017-03-03 67 views
0

我发现我可以在此设置安装打字稿定义使用NPM或分型:我可以安装打字稿定义没有WebStorm/PhpStorm

enter image description here

,因为我并不需要使用的方便typingsnpm来安装这些类型。

但是tsconfig.json中的哪些设置会使WebStorm使用这些定义?在webstorm下载的这些库实际上工作吗?

{ 
    "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" 
    } 
} 

回答

3

配置在Javascript| Libraries中的库仅供PhpStorm本身用于代码完成/导航,但它们不适用于TypeScript编译器服务。 当您通过Settings | Languages & Frameworks | Javascript | Libraries下载Typescript存根时,它们被放置在~/.PhpStorm*/config/javascript/extLibs/中。这对于PhpStorm来说非常好,但是tsc编译器确实需要将d.ts文件放置在项目目录中的某处。 因此,要获得下载的可用于Typescript编译器的存根,您需要将它们复制/移动到您的项目目录(并可能重命名为更具人性化的名称:))。然后,他们将可用于PhpStorm和编译器。 我们计划在未来的版本中提供一个选项,将文件直接下载到项目文件夹(而不是system/extLibs/),请按照WEB-9237进行更新。相关功能要求:WEB-14413

所以,似乎使用npmnpm install @types/)是最好的解决方案,如果你需要的分型,以提供给打字稿编译

1

您应该使用NPM,但如果你

我仍然在.tsx

enter image description here

tsconfig.json越来越Cannot find module react坚持不这样做,我会建议创建一个typings目录与子目录该模块的名称,本身包含定义文件

-typings 
    -react 
     react.d.ts 

即不excludedtsconfig.json

的理由简单地确保该分型目录是编译路径的一部分背后让他们在你的项目中是这些文件包含版本化的代码,就像你的打字稿文件的其余部分一样

当你改变库的版本时,最有可能的定义文件也需要改变,以反映新的和弃用的特征es(你不希望npm为你管理它)