Definitelytyped: 였λ₯˜ TS2304: 'Set' 이름을 찾을 수 μ—†μŠ΅λ‹ˆλ‹€. 815 allowedNodeEnvironmentFlags: μ„€μ •<string>;</string>

에 λ§Œλ“  2018λ…„ 09μ›” 25일  Β·  20μ½”λ©˜νŠΈ  Β·  좜처: DefinitelyTyped/DefinitelyTyped

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)

μ–΄λ–»κ²Œ ν•΄μ•Ό ν•˜λ‚˜μš”?

κ°€μž₯ μœ μš©ν•œ λŒ“κΈ€

target 및 lib 와 es6 와 λ™μΌν•©λ‹ˆλ‹€.
@types/[email protected] λ₯Ό μ„€μΉ˜ν•˜μ—¬ 이 문제λ₯Ό ν•΄κ²°ν–ˆμŠ΅λ‹ˆλ‹€.

λͺ¨λ“  20 λŒ“κΈ€

"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] λ₯Ό μ„€μΉ˜ν•˜μ—¬ 이 문제λ₯Ό ν•΄κ²°ν–ˆμŠ΅λ‹ˆλ‹€.

문제 ν•΄κ²°

이 νŽ˜μ΄μ§€κ°€ 도움이 λ˜μ—ˆλ‚˜μš”?
0 / 5 - 0 λ“±κΈ‰