もう一度サラからやってみるか。
サラからやった記録。
TmpTsDev > which tsc C:\Users\m-hiyama\AppData\Roaming\npm\tsc.ps1 TmpTsDev > tsc --version Version 4.6.2
- ディレクトリを作る。
- map.ts を作る。
- グローバルのtscでコンパイルする。
var map:Map<number, string>; map = new Map<number, string>(); map.set(3, "hello"); console.log(map.get(3));
TmpTsDev > tsc .\map.ts map.ts:1:9 - error TS2583: Cannot find name 'Map'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2015' or later. 1 var map:Map<number, string>; ~~~ map.ts:3:11 - error TS2552: Cannot find name 'Map'. Did you mean 'map'? 3 map = new Map<number, string>(); ~~~ map.ts:1:5 1 var map:Map<number, string>; ~~~ 'map' is declared here. Found 2 errors in the same file, starting at: map.ts:1
- tsc --lib es2021 map.ts とする。
TmpTsDev > tsc --lib es2021 .\map.ts map.ts:6:1 - error TS2584: Cannot find name 'console'. Do you need to change your target library? Try changing the 'lib' compiler option to include 'dom'. 6 console.log(map.get(3)); ~~~~~~~ Found 1 error in map.ts:6
- tsc --lib es2021 -lib dom map.ts とする。
TmpTsDev > tsc --lib es2021 -lib dom .\map.ts error TS2318: Cannot find global type 'Array'. error TS2318: Cannot find global type 'Boolean'. error TS2318: Cannot find global type 'Function'. error TS2318: Cannot find global type 'IArguments'. error TS2318: Cannot find global type 'Number'. error TS2318: Cannot find global type 'Object'. error TS2318: Cannot find global type 'RegExp'. error TS2318: Cannot find global type 'String'. Found 8 errors.
やっぱりこうなる。
- npm install @types/node する。
- tsc .map.ts する。
成功。
- npm uninstall --global @types/node する。
- tsc .map.ts する。
成功。
どうも、グローバルの @types/node は意味なかったようだ。最近の傾向は何でもローカルインストールかも知れない。
- npm uninstall @types/node する。
- tsc .map.ts する。
最初と同じ失敗。ということで、ローカルに ./node_modules/@types/node は必須ということが分かった。
- tsc --showConfig する。
- tsc --init する。
- tsc --showConfig する。
TmpTsDev > tsc --showConfig error TS5081: Cannot find a tsconfig.json file at the current directory: C:/Users/m-hiyama/Work/TmpTsDev.
TmpTsDev > tsc --showConfig { "compilerOptions": { "target": "es2016", "module": "commonjs", "esModuleInterop": true, "forceConsistentCasingInFileNames": true, "strict": true, "skipLibCheck": true }, "files": [ "./map.ts" ] }