D:\workshop\www
λ node -v
v8.12.0
D:\workshop\www
λ npm -v
6.4.1
D:\workshop\www
λ npm install typescript -g
C:\Users\dell\AppData\Roaming\npm\tsc -> C:\Users\dell\AppData\Roaming\npm\node_modules\typescript\bin\tsc
C:\Users\dell\AppData\Roaming\npm\tsserver -> C:\Users\dell\AppData\Roaming\npm\node_modules\typescript\bin\tsserver
+ [email protected]
updated 1 package in 3.061s
D:\workshop\www
λ tsc --version
Version 3.0.3
D:\workshop\www
λ mkdir typescript_learning
D:\workshop\www
λ cd typescript_learning
D:\workshop\www\typescript_learning
λ npm init -y
Wrote to D:\workshop\www\typescript_learning\package.json:
{
"name": "typescript_learning",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}
D:\workshop\www\typescript_learning ([email protected])
λ tsc --init
message TS6071: Successfully created a tsconfig.json file.
D:\workshop\www\typescript_learning ([email protected])
λ npm install @types/node --dev-save
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN [email protected] No description
npm WARN [email protected] No repository field.
+ @types/[email protected]
added 1 package from 30 contributors in 1.657s
D:\workshop\www\typescript_learning ([email protected])
λ touch helloworld.ts
D:\workshop\www\typescript_learning ([email protected])
λ tsc helloworld.ts
node_modules/@types/node/index.d.ts:815:38 - error TS2304: Cannot find name 'Set'.
815 allowedNodeEnvironmentFlags: Set<string>;
helloworld.ts
var a:string = "HelloWorld"
console.log(a)
私は何をすべきか?
"lib": ["es6"]
以上を追加します。
同じ問題が発生していますが、 tsconfig
ファイルにlib
オプションを追加しても解決しませんでした。
Typescriptバージョン:3.1.1
ノードタイピングバージョン:10.11.5
$ mkdir test
$ cd test
$ npm init -y
$ npm install --save-dev typescript @types/node
$ echo 'console.log("test")' > index.ts
$ ./node_modules/.bin/tsc --init
Add lib: "es2015" to tsconfig.json
$ ./node_modules/.bin/tsc index.ts
node_modules/@types/node/index.d.ts:815:38 - error TS2583: Cannot find name 'Set'. Do you need to change your target library? Try changing the `lib` compiler option to es2015 or later.
815 allowedNodeEnvironmentFlags: Set<string>;
私はこれについて多くの人に話しました、 lib
がそれを修正しない場合、ある時点でtsconfigが正しくロードされていない場合は、 include
を使用してlibがファイルと一緒に正しくロードされていることを確認してくださいtsconfig.jsonのfiles
オプション。
@ andy-ms Set
の変更を元に戻す必要がありますか?
人々は実際にはノードで使用するために>es6
libを使用する必要がありますが、これは重大な変更と見なされる可能性があります。
--lib es5
で機能するように、 node/index.d.ts
のinterface SetConstructor {}
$の下に$ interface Set<T> {}
を定義できると思います。
同じ問題。
☁ jest-codelab [master] ⚡ $(npm bin)/tsc ./src/@types/index.ts
node_modules/@types/node/index.d.ts:815:38 - error TS2583: Cannot find name 'Set'. Do you need to change your target library? Try changing the `lib` compiler option to es2015 or later.
815 allowedNodeEnvironmentFlags: Set<string>;
~~~
tsconfig.json
:
"lib": ["es2015", "es2016"]
package.json
:
"devDependencies": {
"@types/jest": "^23.3.3",
"@types/node": "^10.11.4",
"jest": "^23.6.0",
"ts-jest": "^23.10.4",
"tslint": "^5.11.0",
"typescript": "^3.1.1"
}
@mrdulin allowedNodeEnvironmentFlags: ReadonlySet<string>;
があり、 interface ReadonlySet<T> {}
が@types/node/index.d.ts
で宣言されているため、最新の@types/node
がインストールされていないことがわかります(現在は10.12.0)。 @types/node/index.d.ts
。
@andy-msありがとう。 npm rm @types/node -D
の後、この問題はなくなりました。
同じ問題があり、 tsconfig.json
でcompilerOptions.types
を使用して解決します。 したがって、基本的には、そのプロパティに必要な@types
パッケージのみをリストしました。
@ rannie-peraltaこの問題は、空のReadonlySet
宣言を行うことで、タイプが長い間修正されています。
私も同じような問題に遭遇しました。
package.json
{{
"名前": "地図"、
「バージョン」:「1.0.0」、
"説明": ""、
"main": "index.js"、
"スクリプト":{
"test": "echo \"エラー:テストが指定されていません\" && exit 1"
}、
「キーワード」:[]、
"著者": ""、
「ライセンス」:「ISC」、
「依存関係」:{
"typescript": "^ 3.4.5"
}
}
tsconfig.json
{{
"compilerOptions":{
"モジュール": "amd"、
"noImplicitAny":true、
"esModuleInterop":true、
"sourceMap":true、
"jsx": "react"、
"jsxFactory": "tsx"、
"ターゲット": "es6"、
「experimentalDecorators」:true、
"preserveConstEnums":true、
"suppressImplicitAnyIndexErrors":true、
"lib":["es2015"、 "es2016"]
}、
"含む": [
"./src/*"
]、
"除外":[
「node_modules」
]
}
index.js
関数displayData(){
var myMap = new Map();
myMap.set( "name"、 "xxxxxxxx");
}
jsファイルに変換するコマンド
tsc .src \ index.ts
エラー :
src/index.ts:4:21 - error TS2583: Cannot find name 'Map'. Do you need to change your target library? Try changing the
lib`コンパイラオプションをes2015以降に。
4 var myMap = new Map();
~~~
エラーが1つ見つかりました。`
@ Praveer1981解決策は、文字通りエラーメッセージにあります。
私はこれと同じ問題に遭遇し、tsconfig.jsonがエラーメッセージの内容を正確に示しているため、混乱しました。 tsconfig.jsonをさらに変更しても、問題は修正されません。
tsc
にファイルパスを渡すと、 tsconfig.json
は無視されると思います。 これが私に起こっていたことです。
tsc src/foo.ts
#ライブラリ/ターゲットをアップグレードすることを示すコンパイラエラーが発生します
tsc
#tsconfig.jsonがes2015以降のターゲットを指定していたため、正常に動作します
したがって、これを取得してtsconfig.jsonに問題がない場合は、カスタムパスをコンパイラに渡しているかどうかを再確認し、構成を無視する可能性があります。
こっちも一緒
node_modules / @ types / react / index.d.ts:377:23-エラーTS2583:名前'Set'が見つかりません。 ターゲットライブラリを変更する必要がありますか?
lib
コンパイラオプションをes2015以降に変更してみてください。
interactions: Set<SchedulerInteraction>,
構成:
{
"compilerOptions": {
"target": "es5",
"target: "es5", // <= doesn't help
"lib": [
"dom",
"dom.iterable",
"esnext",
"es2015", // <= doesn't help
"es6", // <= doesn't help
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"sourceMap": true,
"baseUrl": "./",
"jsx": "preserve"
},
"include": [
"./**/*",
"*.tsx"
],
"exclude": [
"node_modules",
"**/*.spec.ts"
]
}
私が解析したファイルは次のようになります。
class Greeter {
public greeting: string;
constructor(msg: string) {
this.greeting = msg;
}
}
let g = new Greeter('hello');
export { Greeter };
ここでは、 target
とlib
をes6
と同じです。
@types/[email protected]
をインストールすることで、これを修正することができました。
@brunobertoldi
はい、確認できます。 あなたの答えは問題を解決します。
ここhttps://github.com/DefinitelyTyped/DefinitelyTyped/issues/29172#issuecomment-527708175
@brunobertoldi 、これに加えて、これらのタイピングをインストールするために管理者権限でプロンプトを開く必要がありましたが、一度実行すると機能しました。
ちなみに、ありがとうございます。
追加の詳細をありがとう、@ thomasio101!
ここでは、
target
とlib
をes6
と同じです。
@types/[email protected]
をインストールすることで、これを修正することができました。
かっこいい!
create-react-app
の仕組みに従うことをお勧めします
compilerOptionsの内部
...
"skipLibCheck": true,
"lib": [
"dom",
"dom.iterable",
"esnext"
],
...
libの内容は完全にあなた次第です。
ここでは、
target
とlib
をes6
と同じです。
@types/[email protected]
をインストールすることで、これを修正することができました。
問題を解決する
最も参考になるコメント
ここでは、
target
とlib
をes6
と同じです。@types/[email protected]
をインストールすることで、これを修正することができました。