我读了TypeScript 模块解析的工作原理.
我有以下存储库:ts-di.编译目录结构后如下:
??? dist
? ??? annotations.d.ts
? ??? annotations.js
? ??? index.d.ts
? ??? index.js
? ??? injector.d.ts
? ??? injector.js
? ??? profiler.d.ts
? ??? profiler.js
? ??? providers.d.ts
? ??? providers.js
? ??? util.d.ts
? ??? util.js
??? LICENSE
??? package.json
??? README.md
??? src
? ??? annotations.ts
? ??? index.ts
? ??? injector.ts
? ??? profiler.ts
? ??? providers.ts
? ??? util.ts
??? tsconfig.json
Run Code Online (Sandbox Code Playgroud)
在我的package.json中,我写道"main": "dist/index.js".
在Node.js中一切正常,但TypeScript:
import {Injector} from …Run Code Online (Sandbox Code Playgroud) 我正在尝试从react-materialize导入组件 -
import {Navbar, NavItem} from 'react-materialize';
Run Code Online (Sandbox Code Playgroud)
但是当webpack正在编译时,.tsx它会引发上述错误 -
ERROR in ./src/common/navbar.tsx
(3,31): error TS7016: Could not find a declaration file for module 'react-materi
alize'. 'D:\Private\Works\Typescript\QuickReact\node_modules\react-materialize\l
ib\index.js' implicitly has an 'any' type.
Run Code Online (Sandbox Code Playgroud)
任何解决方案.我不确定如何解决此import语句ts-loader与webpack一起使用.
该index.js反应-兑现长相很喜欢这一点.但是如何在我自己的文件中为模块导入解决这个问题..
https://github.com/react-materialize/react-materialize/blob/master/src/index.js
我在 Windows 10 上使用带有 Visual Studio Code 的 TypeScript 来开发 NPM 模块。我将 mocha/chai 与 nyc (istanbul) 结合使用进行单元测试和代码覆盖。
对于我的一些测试,我想使用 chai-bytes 更容易地比较缓冲区。不幸的是,chai-bytes 模块中没有类型定义文件,@types/chai-bytes 中也没有可用的定义。
因此,我为 chai-bytes 插件编写了自己的类型定义文件(非常简单),但在执行过程中npm test出现以下错误:
TSError: ? Unable to compile TypeScript:
test/utls/BitArray-test.ts(3,23): error TS7016: Could not find a declaration file for module 'chai-bytes'. 'C:/Users/<user>/Source/Repos/velux-api/node_modules/chai-bytes/index.js' implicitly has an 'any' type.
Try `npm install @types/chai-bytes` if it exists or add a new declaration (.d.ts) file containing `declare module 'chai-bytes';`
test/utls/BitArray-test.ts(48,38): error TS2339: Property 'equalBytes' does not exist on type …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用我创建的 nodejs 包,有人可以指出我做错了什么。
这是包结构的样子:
node_modules
|__my_commons
| |__dist
| |__src
| | |__helpers.d.ts
| | |__helpers.js
| | |__index.d.ts
| | |__index.js
| |__node_modules <=This got recursively installed
| |__.npmignore
| |__package.json
src
|_app/app.component.ts <= Here I am using it
Run Code Online (Sandbox Code Playgroud)
my_commons/package.json
{
"_args": [
[
{
"raw": "my_commons@bitbucket:ishan_dutta/my_commons",
"scope": null,
"escapedName": "my_commons",
"name": "my_commons",
"rawSpec": "bitbucket:ishan_dutta/my_commons",
"spec": "bitbucket:ishan_dutta/my_commons",
"type": "hosted",
"hosted": {
"type": "bitbucket",
"ssh": "git@bitbucket.org:ishan_dutta/my_commons.git",
"sshUrl": "git+ssh://git@bitbucket.org/ishan_dutta/my_commons.git",
"httpsUrl": "git+https://bitbucket.org/ishan_dutta/my_commons.git",
"shortcut": "bitbucket:ishan_dutta/my_commons",
"directUrl": "https://bitbucket.org/ishan_dutta/my_commons/raw/master/package.json"
}
},
"/Users/ishandutta2007/Documents/Projects/my_proj"
]
],
"_from": …Run Code Online (Sandbox Code Playgroud) typescript ×3
node-modules ×2
node.js ×2
angularjs ×1
chai ×1
javascript ×1
mocha.js ×1
nyc ×1
reactjs ×1
webpack ×1
webpack-2 ×1