typescript : 오류 TS2693 : 'Promise'는 유형 만 참조하지만 여기서 값으로 사용 중입니다.
AWS Lambda에 Typescript를 사용하려고하는데 약속을 사용할 때마다 다음과 같은 오류가 발생합니다.
오류 TS2693 : 'Promise'는 유형 만 참조하지만 여기서 값으로 사용 중입니다.
코드에서 다음 변형을 사용해 보았습니다.
Promise 생성자 사용
responsePromise = new Promise((resolve, reject) => {
return reject(new Error(`missing is needed data`))
})
Promise.reject 사용
responsePromise = Promise.reject(new Error(`Unsupported method "${request.httpMethod}"`));
버전
다음은 내 개발자 종속성의 버전입니다.
"typescript": "^2.2.2"
"@types/aws-lambda": "0.0.9",
"@types/core-js": "^0.9.40",
"@types/node": "^7.0.12",
tsconfig.json의 내용
{
"compileOnSave": true,
"compilerOptions": {
"module": "commonjs",
// "typeRoots" : ["./typings", "./node_modules/@types"],
"target": "es5",
// "types" : [ "core-js" ],
"noImplicitAny": true,
"strictNullChecks": true,
"allowJs": true,
"noEmit": true,
"alwaysStrict": true,
"preserveConstEnums": true,
"sourceMap": true,
"outDir": "dist",
"moduleResolution": "Node",
"declaration": true,
"lib": [
"es6"
]
},
"include": [
"index.ts",
"lib/**/*.ts"
],
"exclude": [
"node_modules",
"**/*.spec.ts"
]
}
ts 작업을 실행하기 위해 다음 구성으로 grunt-ts를 사용하고 있습니다.
ts: {
app: {
tsconfig: {
tsconfig: "./tsconfig.json",
ignoreSettings: true
}
},
...
I는 언급 된 수용액으로 시도 I 얻을 [TS] '미스'만 입력을 지칭하지만 여기에 값으로 사용되고 있지만 운.
와 같은 문제가 있었고 aws-sdk
를 사용하여 해결했습니다 "target": "es2015"
. 이것은 내 tsconfig.json
파일입니다.
{
"compilerOptions": {
"outDir": "./dist/",
"sourceMap": false,
"noImplicitAny": false,
"module": "commonjs",
"target": "es2015"
},
"include": [
"src/**/*"
],
"exclude": [
"node_modules",
"**/*.spec.ts"
]
}
오늘 같은 오류가 발생하여 다음과 같이 해결했습니다.
npm i --save-dev @types/es6-promise
최신 정보:
더하다:
import {Promise} from 'es6-promise'
tsconfig.json 파일에 아래 코드를 추가 하여이 문제를 해결했습니다.
"lib": [
"ES5",
"ES2015",
"DOM",
"ScriptHost"]
compilerOptions 에서 대상 을 변경하여 해결되었습니다 .
{
"compilerOptions": {
"module": "es2015",
"target": "es2015",
"lib": [
"es2016",
"dom"
],
"moduleResolution": "node",
"noImplicitAny": false,
"sourceMap": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"outDir": "./public/js/app"
},
"exclude": [
"node_modules",
"public/js",
"assets/app/polyfills.ts"
],
"angularCompilerOptions": {
"skipMetadataEmit": true
}
}
여기 내 팁이 있습니다. vscode 1.21.1로 테스트 (MAC)
tsconfig.json에 구성을 넣으십시오.
"lib": [
"es2016",
"dom"
]
에 compilerOptions
IDE를 다시 시작하십시오 (이 조치가 필요합니다 : D).
오류가 발생하는 파일에 아래 줄을 추가하십시오.
declare var Promise: any;
추신 : 이것은 확실히 최적의 솔루션이 아닙니다
이 오류가 있었지만이 명령을 사용하여 문제를 해결했습니다. 내 ts 파일 이름은 promises-fs.ts입니다.
tsc promises-fs.ts --target es6 && node promises-fs.js
그리고 오류는 사라졌다
마지막으로 tsc는 오류없이 작동하기 시작했습니다. 그러나 여러 변경 사항이 있습니다. 덕분에 산드로 카일 , 뾰족한 & unional
- dt ~ aws-lambda 제거
- Removed options like noEmit,declaration
- Modified Gruntfile and removed ignoreSettings
tsconfig.json
{
"compileOnSave": true,
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"noImplicitAny": false,
"strictNullChecks": true,
"alwaysStrict": true,
"preserveConstEnums": true,
"sourceMap": false,
"moduleResolution": "Node",
"lib": [
"dom",
"es2015",
"es5",
"es6"
]
},
"include": [
"*",
"src/**/*"
],
"exclude": [
"./node_modules"
]
}
Gruntfile.js
ts: {
app: {
tsconfig: {
tsconfig: "./tsconfig.json"
}
},
...
Had the same issue with typescript and the aws-sdk
. The solve was to change the target to es6
.
My complete tsconfig.json
file:
{
compilerOptions: {
outDir: ./dist/,
sourceMap: true,
noImplicitAny: true,
module: commonjs,
target: es6,
jsx: react,
allowJs: true
},
include: [
./src/**/*
]
}
I had the same issue until I added the following lib array in typeScript 3.0.1
tsconfig.json
{
"compilerOptions": {
"outDir": "lib",
"module": "commonjs",
"allowJs": false,
"declaration": true,
"target": "es5",
"lib": ["dom", "es2015", "es5", "es6"],
"rootDir": "src"
},
"include": ["./**/*"],
"exclude": ["node_modules", "**/*.spec.ts"]
}
Core-js did not work for me as it caused other issues, however, simply installing the latest version of npm i @types/es6-promise --save-dev
got rid of the issues. The issues for me stemmed from compiling an sdk that was using rxjs. Here is the error I was getting:
`node_modules/rxjs/Observable.d.ts(59,60): error TS2693: Promise only refers to a type, but is being used as a value here.`
None of the up-voted answers here work for me. Here is a guaranteed and reasonable solution. Put this near the top of any code file that uses Promise...
declare const Promise: any;
If you're using the DefinitelyTyped repository in your project you might be experiencing this recent issue.
A decent workaround you might use (other than waiting for an updated build of the definitions file or refactoring your TS code) is to specify an explicit version+build for the core-js typings rather than let Visual Studio pick the latest/most recent one. I found one that seems to be unaffected by this problem (in my case at least), you can use it replacing the following line from your package.json file:
"scripts": {
"postinstall": "typings install dt~core-js --global"
}
With the following one:
"scripts": {
"postinstall": "typings install dt~core-js@0.9.7+20161130133742 --global"
}
This fixed my issue for good. However, is highly recommended to remove the explicit version+build reference as soon as the issue will be released.
For further info regarding this issue, you can also read this blog post that I wrote on the topic.
Well, this might be counter-intuitive but I solved this adding esnext
to my lib
.
{
"compilerOptions": {
"lib": [
"esnext"
],
"target": "es5",
}
}
The FIX, as suggested by the compiler is to
Try changing the
lib
compiler option to es2015 or later.
I had the same problem and this saved me from the problem in second:
write in console this:
npm i --save bluebird
npm i --save-dev @types/bluebird @types/core-js@0.9.36
in the file where the problem is copy paste this:
import * as Promise from 'bluebird';
Just change the target to "ES2017" in tsconfig.json file.
this is my tsconfig.json file
{
"compilerOptions": {
/* Basic Options */
"target": "ES2017", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
"declaration": true, /* Generates corresponding '.d.ts' file. */
"sourceMap": true, /* Generates corresponding '.map' file. */
"outDir": "./dist", /* Redirect output structure to the directory. */
"strict": true /* Enable all strict type-checking options. */
},
"include": [
"src/**/*"
],
"exclude": [
"node_modules"
]
}
npm i --save-dev @types/es6-promise
after up command, you'd better check tsconfig.json make sure the "target" must great than "es6". maybe tsc not support es5 yet.
Having spent lot of time trying to fix this. I had no luck with any solution provide here or elsewhere.
But then later realised it wasn't so much as just solving the issue. But you also need to RESTART the VSCODE for it to take affect.
'Programming' 카테고리의 다른 글
열거 형 값에 대한 사용자 지정 문자열 형식을 가진 열거 형 콤보 상자를 사용하려면 어떻게합니까? (0) | 2020.06.27 |
---|---|
PHP 페이지 HTML 출력을 축소하는 방법? (0) | 2020.06.27 |
Objective-C의 MD5 알고리즘 (0) | 2020.06.27 |
MYSQL 잘린 잘못된 DOUBLE 값 (0) | 2020.06.27 |
클래스 선택기와 속성 선택기를 jQuery와 결합 (0) | 2020.06.27 |