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>;
μλ νμΈμ.
var a:string = "HelloWorld"
console.log(a)
μ΄λ»κ² ν΄μΌ νλμ?
"lib": ["es6"]
μ΄μμ μΆκ°νμΈμ.
λμΌν λ¬Έμ κ° μμ§λ§ tsconfig
νμΌμ lib
μ΅μ
μ μΆκ°ν΄λ λ¬Έμ κ° ν΄κ²°λμ§ μμ΅λλ€.
νμ΄νμ€ν¬λ¦½νΈ λ²μ : 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λ₯Ό μ¬μ©ν΄μΌ νμ§λ§ μ΄κ²μ νκΈ°μ μΈ λ³κ²½μΌλ‘ _λ³Ό μ μμ΅λλ€_.
node/index.d.ts
interface SetConstructor {}
interface Set<T> {}
λ₯Ό μ μνμ¬ --lib es5
μ ν¨κ» μλνλλ‘ ν μ μλ€κ³ μκ°ν©λλ€.
κ°μ λ¬Έμ .
β 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 μ΅μ @types/node
κ° μ€μΉλμ΄ μμ§ μλ€κ³ λ§ν μ μμ΅λλ€(νμ¬ 10.12.0). allowedNodeEnvironmentFlags: ReadonlySet<string>;
κ° μκ³ interface ReadonlySet<T> {}
κ° @types/node/index.d.ts
μ μ μΈλμ΄ μκΈ° λλ¬Έμ
λλ€.
@andy-ms κ°μ¬ν©λλ€. npm rm @types/node -D
μ΄νμλ μ΄ λ¬Έμ κ° μ¬λΌμ‘μ΅λλ€.
λλ κ°μ λ¬Έμ κ° μμΌλ©° tsconfig.json
$ μμ compilerOptions.types
λ₯Ό μ¬μ©νμ¬ ν΄κ²°ν©λλ€. λ°λΌμ κΈ°λ³Έμ μΌλ‘ ν΄λΉ μμ±μ νμν @types
ν¨ν€μ§λ§ λμ΄νμ΅λλ€.
@rannie-peralta μ΄ λ¬Έμ λ λΉ ReadonlySet
μ μΈμ μννμ¬ μ νμμ μ€λ«λμ μμ λμμ΅λλ€.
λλ κ°μ μ’
λ₯μ λ¬Έμ κ° λ°μνμ΅λλ€.
ν¨ν€μ§.json
{
"μ΄λ¦": "μ§λ",
"λ²μ ": "1.0.0",
"μ€λͺ
": "",
"λ©μΈ": "index.js",
"μ€ν¬λ¦½νΈ": {
"ν
μ€νΈ": "μμ½ \"μ€λ₯: μ§μ λ ν
μ€νΈ μμ\" && μ’
λ£ 1"
},
"ν€μλ": [],
"μκ°": "",
"λΌμ΄μΌμ€": "ISC",
"μ’
μμ±": {
"typescript": "^3.4.5"
}
}
tsconfig.json
{
"μ»΄νμΌλ¬ μ΅μ
": {
"λͺ¨λ": "AMD",
"noImplicitAny": μ°Έ,
"esModuleInterop": μ°Έ,
"sourceMap": μ°Έ,
"jsx": "λ°μ",
"jsxFactory": "tsx",
"λμ": "es6",
"μ€νμ μΈ λ°μ½λ μ΄ν°": true,
"preserveConstEnums": μ°Έ,
"suppressImplicitAnyIndexErrors": μ°Έ,
"lib": ["es2015", "es2016"]
},
"ν¬ν¨": [
"./src/*"
],
"μ μΈ": [
"λ
Έλ λͺ¨λ"
]
}
index.js
ν¨μ νμ λ°μ΄ν°(){
var myMap = μλ‘μ΄ μ§λ();
myMap.set("μ΄λ¦","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
# λ΄ lib/targetμ μ
κ·Έλ μ΄λνλΌλ μ»΄νμΌλ¬ μ€λ₯κ° λ°μν©λλ€.
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
μλ λ°©μμ λ°λ₯΄λ κ²μ΄ μ’μ΅λλ€.
μ»΄νμΌλ¬ μ΅μ λ΄λΆ
...
"skipLibCheck": true,
"lib": [
"dom",
"dom.iterable",
"esnext"
],
...
libμ λ΄μ©μ μ μ μΌλ‘ κ·νμκ² λ¬λ € μμ΅λλ€.
target
λ°lib
μes6
μ λμΌν©λλ€.
@types/[email protected]
λ₯Ό μ€μΉνμ¬ μ΄ λ¬Έμ λ₯Ό ν΄κ²°νμ΅λλ€.
λ¬Έμ ν΄κ²°
κ°μ₯ μ μ©ν λκΈ
target
λ°lib
μes6
μ λμΌν©λλ€.@types/[email protected]
λ₯Ό μ€μΉνμ¬ μ΄ λ¬Έμ λ₯Ό ν΄κ²°νμ΅λλ€.