본문 바로가기

개발하자

TypeScript 컴파일에서 실험 장식자 경고

반응형

TypeScript 컴파일에서 실험 장식자 경고

나는 경고를 받았다...

데코레이터에 대한 실험적인 지원은 향후 릴리즈에서 변경될 수 있는 기능입니다. 이 경고를 제거하려면 '실험 장식자' 옵션을 설정합니다.

... tsconfig.json의 컴파일러 옵션 설정이 다음과 같은 경우에도 마찬가지입니다:

"emitDecoratorMetadata": true,
"experimentalDecorators": true,

이상한 것은 장식자를 사용하는 일부 랜덤 클래스는 경고를 표시하지 않지만 동일한 프로젝트의 나머지 클래스는 경고를 표시한다는 것입니다.

무엇이 TypeScript 컴파일러에서 이러한 동작을 발생시킬 수 있습니까?




VS Code는 TypeScript 프로젝트를 위한 훌륭한 편집자이지만, 때때로 킥이 필요합니다. 종종, 경고 없이 특정 파일들이 그것을 놀라게 하고 불평하게 만든다. 대부분의 해결책은 열려 있는 모든 파일을 저장하고 닫은 다음 여는 것으로 보입니다. 그러면 문제가 되는 파일을 오류 없이 다시 열 수 있습니다. 효과가 없으면 거품을 내고 헹구고 반복하세요.

배열을 사용하여 원본 파일을 지정하는 경우 IntelliSense는 VS Code가 입력 파일 트리를 통과하여 찾을 수 있도록 해당 파일을 참조하는 경우에만 올바르게 작동합니다.

편집: 'reload window' 명령(지금은 오래 전에 추가)을 사용하면 이 문제를 완전히 해결할 수 있습니다.




내 것에 추가해야 한다:

"typescript.tsdk": "node_modules/typescript/lib"



다음 위치에서 파일 열기

또는 아래에 언급된 메뉴에서 파일을 열 수 있습니다

VSCode -> File -> Preferences -> Workspace Settings

experimentalDecorators settings

그런 다음 파일에 다음 행을 추가합니다

{
    "typescript.tsdk": "node_modules/typescript/lib",
    "enable_typescript_language_service": false
}

그게 다예요. "에 대한 경고/오류가 표시되지 않습니다




명확성과 어리석음을 위해서.

1) .vscode/settings.json을 엽니다.

2) 여기에 "typescript.tsdk": "node_modules/typescript/lib"를 추가합니다.

3) 살려주세요.

4) Visual Studio Code를 다시 시작합니다.




tsconfig.json 파일에서 "baseUrl": ","을 제거하여 경고를 수정했습니다




이 오류는 작업영역 폴더에 대해 "src" 폴더를 선택할 때도 발생합니다.

루트 폴더, "src", "node_modules"가 위치한 폴더를 선택하면 오류가 사라집니다




이 답변은 프로젝트가 아닌 프로젝트를 사용하는 사용자를 대상으로 합니다. 파일 대신 파일을 사용할 수 있습니다.

파일 내부에 경고를 기록하려는 경우:

{
    "compilerOptions": {
        "experimentalDecorators": true
    }
}

요청된 버그 동작의 경우 항상 구성 파일에 "포함"을 지정하고 편집기를 다시 시작하는 것이 좋습니다. 예.

{
    "compilerOptions": {
        "target": "ES6",
        "experimentalDecorators": true
    },
    "include": [
        "app/**/*"
    ],
    "exclude": [
        "node_modules"
    ]
}



프로젝트 내에서 tsconfig.json 파일을 만든 다음 이 줄을 추가합니다

{
    "compilerOptions": {
        "experimentalDecorators": true,
        "allowJs": true
    }
}



project-name/src 대신 전체 프로젝트의 폴더 열기

tsconfig.json이 src 폴더를 벗어났습니다




프로젝트 외부에 있는 TS 파일을 여는 경우 이 문제가 발생할 수 있습니다. 예를 들어, 나는 Lerna를 사용하고 있고 다른 패키지에서 파일을 열었어. 비록 그 다른 패키지는 실험적인 장식자들과 함께 자체적인 tsconfig를 가지고 있었지만, VsCode는 그것을 존중하지 않는다.




저는 Angular 2에서 서비스를 만드는 동안 같은 문제에 직면했습니다. 나는 tsconfig.json에 있는 모든 것을 가지고 있다.여전히 ColorsImplable 라인에서 이 오류가 발생하고 있었습니다.

@Injectable()
export class ColorsImmutable {

그리고 해결책은 공급자 어레이를 사용하여 모듈 레벨 또는 구성요소 레벨에서 서비스를 등록하는 것이었습니다.

providers:[ColorsImmutable ],



Visual studio에서 작업 중인 경우. 이 방법을 시도해 보세요

  1. 비주얼 스튜디오에서 프로젝트 언로드
  2. 프로젝트 홈 디렉토리로 이동하여 "csproj" 파일을 엽니다.
  3. 이미지에 표시된 것처럼 이 섹션에 TypeScript Experimental 데코레이터 추가

    enter image description here

    1. Visual studio에서 프로젝트를 다시 로드합니다.

자세한 내용은 해당 위치를 참조하십시오.




  1. VS 코드를 엽니다.
  2. ctrl+쉼표 누르기
  3. 의 지침을 따릅니다



경고를 제거하려면 vcode의 settings.json 파일에 다음을 추가해야 합니다.

"javascript.implicitProjectConfig.experimentalDecorators": true

VS 코드 -> 기본 설정 -> 설정

enter image description here

갱신하다

Clepsyd가 지적했듯이, 이 설정은 더 이상 사용되지 않았습니다. 지금 바로 사용해야 합니다

"js/ts.implicitProjectConfig.experimentalDecorators":true

enter image description here




tsconfig.json에 이 옵션을 추가했습니다. 프론트엔드를 angular-cli 프로젝트 이름으로 바꿉니다.




tsconfig.json에 다음 행을 추가하고 VS Code를 다시 시작합니다.

{
    "compilerOptions": {
        "experimentalDecorators": true,
        "target": "es5",
        "allowJs": true
    }
}



"javascript.implicitProjectConfig.experimentalDecorators": true

이 문제를 해결할 것이다.




요점을 강조하지는 않지만 다음 사항을 반드시 추가해야 합니다

  • 사용자 설정이 아닌 작업 공간 설정

파일 >> 환경설정 >> 설정에서

"javascript.implicitProjectConfig.experimentalDecorators": true

이것은 나에게 문제를 해결했고, 나는 내가 여기와 다른 곳에서 찾은 꽤 많은 제안들을 시도했다.




cli를 사용하여 *.ts 파일을 컴파일하는 경우 다음 명령을 사용하여 실험용 데코레이터를 설정할 수 있습니다:

 tsc filename.ts --experimentalDecorators "true"



src 폴더만 열면 ts.config.json(프로젝트 폴더에 위치) 파일이 범위를 벗어나 VS 코드에서 전체 프로젝트의 폴더를 열었는지 확인하십시오.

나의 경우 이것이 이 문제와 관련된 모든 문제를 해결했다.




최근 Visual Studio 2017에서 이 문제가 발생했습니다. 알고 보니 VS -의 "기능" 때문이었습니다.

따라서 빌드 작업을 컨텐츠로 변경하고 솔루션을 다시 로드하여 문제를 해결했습니다.




파일 -> 환경설정 -> 설정




를 사용해 볼 수도 있습니다. 방금 앱을 재구축했는데 이제는 이를 준수하지 않습니다.




Visual Code Studio에서 파일로 이동 >> 기본 설정 > 검색 필드에서 "장식자"를 검색하고 이미지와 같이 옵션을 확인합니다.




따라서 모듈 이름을 파일 이름과 일치시킴으로써 이 문제를 해결할 수 있습니다. 모듈 이름이 BankSpecialtyModule인 경우 파일 이름은 .bank-specialty.module.ts이어야 합니다




VSCode에서 File => Preferences => Settings(또는 Control+comma)로 이동하면 User Settings(사용자 설정) 파일이 열립니다. "javascript.implicitProjectConfig.experimentalDecorators": true를 검색한 다음 파일에 대한 실험 데코레이터 확인란을 선택하면 수정됩니다. 저도 그랬어요.

enter image description here




I experienced this error when I created a new module and move my *.module.ts and *-routing.module.ts file to another folder. After I deleted the two files and created the module on the new folder it works perfectly. Environment Angular Version 9 and Angular CLI version 9.1.0




If you using Deno JavaScript and TypeScript runtime and you enable experimentalDecorators:true in tsconfig.json or the VSCode ide settings. It will not work. According to Deno requirement, you need to provide tsconfig as a flag when running a Deno file. See Custom TypeScript Compiler Options

In my particular case I was running a Deno test and used.

$ deno test -c tsconfig.json

If it is a file, you have something like

 $ deno run -c tsconfig.json mod.ts

my tsconfig.json

{
  "compilerOptions": {
    "allowJs": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "module": "esnext"
  }
}



For me, this error "Experimental support for decorators is a feature that is subject to change in a future release. (etc)" only happened in VS Code in an Angular project and only when creating a new Service.

The solution above: "In Visual Code Studio Go to File >> Preferences >> Settings, Search "decorator" in search field and Checking the option JavaScript › Implicit Project Config: Experimental Decorators" solved the problem.

Also, stopping the ng serve in the terminal window and restarting it made the error disappear after recompile.




Please follow the below step to remove this warning message. enter image description here

Step 1: Go to setting in your IDE then find or search the experimentalDecorators.enter image description here

Step 2: then click on checkbox and warning has been remove in your page.

enter image description here




I had this error with following statement

Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option in your tsconfig or jsconfig to remove this warning.ts(1219)

It was there because my Component was not registered in AppModule or (app.module.ts) i simply gave the namespace like

import { abcComponent } from '../app/abc/abc.component';

and also registered it in declarations




I get this warning displayed in vscode when creating a new Angular service with the

@Injectable({
  providedIn: 'root'
})

syntax (rather than providing the service in app.module.ts).

The warning persists until I reference the new service somewhere in the project. Once the service gets used the warning goes away. No typescript configuration or vscode settings changes necessary.




You can run with this code

 tsc .\src\index.ts --experimentalDecorators "true" --emitDecoratorMetadata "true"



in my case I solved this issue by setting "include": [ "src/**/*"] in my tsconfig.json file and restarting vscode. I've got this solution from a github issue: https://github.com/microsoft/TypeScript/issues/9335




I had the same issues. It was fixed by importing the class with 'decorator warning' by other class.




I used React and Nest for my project. Had this error displayed in the backend, but adding those two lines to react's tsconfig.json fixed the issue for some reason. Furthermore, everything above did not work for me

"compilerOptions": {
    ...
    "experimentalDecorators": true,
    "strictPropertyInitialization": false
},



In my case, I just needed to import the component or module I created into another module(for example the shared module). Somehow this way VS Code realizes the file exists.




This error can also mean that you have an error in tsconfig.json In my case I was moving around a library and didnt fix path

"extends": "../../tsconfig.base.json",

After fixing it, error went away imidiately, no need to restart VS Code.




STEP 1: Press ctrl + , in VS code

STEP 2: Enter 'js/ts.implicitProjectConfig: Experimental Decorators' in search box

STEP 3: check the checkbox related to the search

enter image description here




I resolved the same issue in the VS Code Version:1.76.0 and fixed it by following these steps.

  • Open any TS file > click on the TypeScript at the bottom line Select language mode enter image description here
  • Then click on Configure 'TypeScript' language based settings...
  • it will open the settings.json file enter image description here
  • add line number 3 if it is not there. and save it:
{
    "terminal.integrated.defaultProfile.windows": "PowerShell",
    "js/ts.implicitProjectConfig.experimentalDecorators":true, // Add this line
    "explorer.confirmDelete": false,
    "[typescript]": {
        "editor.defaultFormatter": "esbenp.prettier-vscode"
    },
    "window.zoomLevel": 1
}

반응형