今回react-lazyloadというパッケージの型定義ファイルを作りました。
型定義ファイル自作時のおく場所に関して相談させて下さい
tsconfigを以下のように記載してます
js:tsconfig.js
1"compilerOptions": { 2 "outDir": "build/dist", 3 "module": "commonjs", 4 "target": "es5", 5 "lib": ["es6", "dom"], 6 "jsx": "react", 7 "rootDir": "src", 8 //一部省略 9 "traceResolution": true, 10 "typeRoots" : ["./mytypes","./node_modules/@types"] 11 },
上記のようにtypeRootsに自作した定義ファイルを置く場所を作り以下のように格納しました。
<sampleproject>/mytypes/react-lazyload/index.d.ts
更にtraceResolutionをtrueに設定して
tsc | grep react-lazyload
を実行すると
esolving real path for ‘xxxx/mytypes/react-lazyload/index.d.ts', result ‘xxxx/mytypes/react-lazyload/index.d.ts'. ======== Type reference directive 'react-lazyload' was successfully resolved to ‘xxxx/mytypes/react-lazyload/index.d.ts', primary: true. ========
という風にちゃんと解決したようにみえるのですが
最終的に以下のようなエラーが出ます
src/App.tsx(3,22): error TS7016: Could not find a declaration file for module 'react-lazyload'. 'xxxx/node_modules/react-lazyload/lib/index.js' implicitly has an 'any' type.
また自作ファイル自体を疑いましたが自作した定義ファイルを
xxxx/node_modules/@types/react-lazyload/index.d.ts
に格納するとエラーが出ず上手く動作します。
どこか手順が間違えているのでしょうか?ご教授お願い致します。

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。