Как изменить цель компилятора машинописного текста по умолчанию (TS C) - PullRequest
0 голосов
/ 02 августа 2020

При компиляции этого фрагмента кода TS C продолжает возвращать ошибку:

let message = 'abc';
message.endsWith('c');

В основном компилятор не может найти метод endsWith() для строки типа. Эта же ошибка также возвращается парсером машинописного текста , который я установил для атома . Я понимаю, что это происходит потому, что компилятор нацелен на версию Javascript, в которой нет этого метода для этого типа, который был представлен ES6. Действительно, компиляция с помощью команды tsc --target ES6 code.ts не возвращает никаких ошибок. Однако я бы хотел изменить целевую версию Javascript на более новую, чтобы мне не приходилось каждый раз указывать целевую версию. Это можно сделать в рамках проекта, создав tsconfig. json файл , но есть ли способ изменить его глобально для любого будущего проекта, чтобы мне больше не приходилось об этом беспокоиться?

РЕДАКТИРОВАТЬ: это мой tsconfig. json

{
  "compilerOptions": {
    "target": "es2020"
  }
}

Если он находится в том же каталоге, что и проект, вызов команды tsc в этом каталоге работает отлично. Кроме того, анализатор Atom перестает сигнализировать об ошибке, описанной ранее.

Однако я бы хотел, чтобы этот параметр был действителен для любого проекта машинописного текста, который я мог бы начать в будущем. Поскольку ts c ищет файл tsconfig. json, начиная с заданного каталога и затем поднимаясь по иерархии, размещение этого файла tsconfig. json в каталоге, в котором размещены все каталоги моих проектов, должно решить мою проблему. Однако вместо этого я получаю кучу ошибок, связанных с angular.

PS C:\Users\gianm> cd ts-hello
PS C:\Users\gianm\ts-hello> tsc
../angular-node-express/e2e/src/app.e2e-spec.ts:2:34 - error TS2307: Cannot find module 'protractor' or its corresponding type declarations.

2 import { browser, logging } from 'protractor';
                                   ~~~~~~~~~~~~

../angular-node-express/e2e/src/app.e2e-spec.ts:4:1 - error TS2582: Cannot find name 'describe'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha`.

4 describe('workspace-project App', () => {
  ~~~~~~~~

../angular-node-express/e2e/src/app.e2e-spec.ts:7:3 - error TS2304: Cannot find name 'beforeEach'.

7   beforeEach(() => {
    ~~~~~~~~~~

../angular-node-express/e2e/src/app.e2e-spec.ts:11:3 - error TS2582: Cannot find name 'it'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha`.

11   it('should display welcome message', () => {
     ~~

../angular-node-express/e2e/src/app.e2e-spec.ts:13:5 - error TS2304: Cannot find name 'expect'.

13     expect(page.getTitleText()).toEqual('angular-node-express app is running!');
       ~~~~~~

../angular-node-express/e2e/src/app.e2e-spec.ts:16:3 - error TS2304: Cannot find name 'afterEach'.

16   afterEach(async () => {
     ~~~~~~~~~

../angular-node-express/e2e/src/app.e2e-spec.ts:19:5 - error TS2304: Cannot find name 'expect'.

19     expect(logs).not.toContain(jasmine.objectContaining({
       ~~~~~~

../angular-node-express/e2e/src/app.e2e-spec.ts:19:32 - error TS2304: Cannot find name 'jasmine'.

19     expect(logs).not.toContain(jasmine.objectContaining({
                                  ~~~~~~~

../angular-node-express/e2e/src/app.po.ts:1:38 - error TS2307: Cannot find module 'protractor' or its corresponding type declarations.

1 import { browser, by, element } from 'protractor';
                                       ~~~~~~~~~~~~

../angular-node-express/src/app/app-routing.module.ts:1:26 - error TS2307: Cannot find module '@angular/core' or its corresponding type declarations.

1 import { NgModule } from '@angular/core';
                           ~~~~~~~~~~~~~~~

../angular-node-express/src/app/app-routing.module.ts:2:38 - error TS2307: Cannot find module '@angular/router' or its corresponding type declarations.

2 import { Routes, RouterModule } from '@angular/router';
                                       ~~~~~~~~~~~~~~~~~

../angular-node-express/src/app/app-routing.module.ts:10:14 - error TS1219: 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.

10 export class AppRoutingModule { }
                ~~~~~~~~~~~~~~~~

../angular-node-express/src/app/app.component.spec.ts:1:32 - error TS2307: Cannot find module '@angular/core/testing' or its corresponding type declarations.

1 import { TestBed, async } from '@angular/core/testing';
                                 ~~~~~~~~~~~~~~~~~~~~~~~

../angular-node-express/src/app/app.component.spec.ts:2:37 - error TS2307: Cannot find module '@angular/router/testing' or its corresponding type declarations.

2 import { RouterTestingModule } from '@angular/router/testing';
                                      ~~~~~~~~~~~~~~~~~~~~~~~~~

../angular-node-express/src/app/app.component.spec.ts:5:1 - error TS2582: Cannot find name 'describe'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha`.

5 describe('AppComponent', () => {
  ~~~~~~~~

../angular-node-express/src/app/app.component.spec.ts:6:3 - error TS2304: Cannot find name 'beforeEach'.

6   beforeEach(async(() => {
    ~~~~~~~~~~

../angular-node-express/src/app/app.component.spec.ts:17:3 - error TS2582: Cannot find name 'it'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha`.

17   it('should create the app', () => {
     ~~

../angular-node-express/src/app/app.component.spec.ts:20:5 - error TS2304: Cannot find name 'expect'.

20     expect(app).toBeTruthy();
       ~~~~~~

../angular-node-express/src/app/app.component.spec.ts:23:3 - error TS2582: Cannot find name 'it'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha`.

23   it(`should have as title 'angular-node-express'`, () => {
     ~~

../angular-node-express/src/app/app.component.spec.ts:26:5 - error TS2304: Cannot find name 'expect'.

26     expect(app.title).toEqual('angular-node-express');
       ~~~~~~

../angular-node-express/src/app/app.component.spec.ts:29:3 - error TS2582: Cannot find name 'it'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha`.

29   it('should render title', () => {
     ~~

../angular-node-express/src/app/app.component.spec.ts:33:5 - error TS2304: Cannot find name 'expect'.

33     expect(compiled.querySelector('.content span').textContent).toContain('angular-node-express app is running!');
       ~~~~~~

../angular-node-express/src/app/app.component.ts:1:27 - error TS2307: Cannot find module '@angular/core' or its corresponding type declarations.

1 import { Component } from '@angular/core';
                            ~~~~~~~~~~~~~~~

../angular-node-express/src/app/app.component.ts:8:14 - error TS1219: 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.

8 export class AppComponent {
               ~~~~~~~~~~~~

../angular-node-express/src/app/app.module.ts:1:31 - error TS2307: Cannot find module '@angular/platform-browser' or its corresponding type declarations.

1 import { BrowserModule } from '@angular/platform-browser';
                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~

../angular-node-express/src/app/app.module.ts:2:26 - error TS2307: Cannot find module '@angular/core' or its corresponding type declarations.

2 import { NgModule } from '@angular/core';
                           ~~~~~~~~~~~~~~~

../angular-node-express/src/app/app.module.ts:20:14 - error TS1219: 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.

20 export class AppModule { }
                ~~~~~~~~~

../angular-node-express/src/app/input-user-data-form/input-user-data-form.component.spec.ts:1:50 - error TS2307: Cannot find module '@angular/core/testing' or its corresponding type declarations.

1 import { async, ComponentFixture, TestBed } from '@angular/core/testing';
                                                   ~~~~~~~~~~~~~~~~~~~~~~~

../angular-node-express/src/app/input-user-data-form/input-user-data-form.component.spec.ts:5:1 - error TS2582: Cannot find name 'describe'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha`.

5 describe('InputUserDataFormComponent', () => {
  ~~~~~~~~

../angular-node-express/src/app/input-user-data-form/input-user-data-form.component.spec.ts:9:3 - error TS2304: Cannot find name 'beforeEach'.

9   beforeEach(async(() => {
    ~~~~~~~~~~

../angular-node-express/src/app/input-user-data-form/input-user-data-form.component.spec.ts:16:3 - error TS2304: Cannot find name 'beforeEach'.

16   beforeEach(() => {
     ~~~~~~~~~~

../angular-node-express/src/app/input-user-data-form/input-user-data-form.component.spec.ts:22:3 - error TS2582: Cannot find name 'it'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha`.

22   it('should create', () => {
     ~~

../angular-node-express/src/app/input-user-data-form/input-user-data-form.component.spec.ts:23:5 - error TS2304: Cannot find name 'expect'.

23     expect(component).toBeTruthy();
       ~~~~~~

../angular-node-express/src/app/input-user-data-form/input-user-data-form.component.ts:1:35 - error TS2307: Cannot find module '@angular/core' or its corresponding type declarations.

1 import { Component, OnInit } from '@angular/core';
                                    ~~~~~~~~~~~~~~~

../angular-node-express/src/app/input-user-data-form/input-user-data-form.component.ts:8:14 - error TS1219: 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.

8 export class InputUserDataFormComponent implements OnInit {
               ~~~~~~~~~~~~~~~~~~~~~~~~~~

../angular-node-express/src/main.ts:1:32 - error TS2307: Cannot find module '@angular/core' or its corresponding type declarations.

1 import { enableProdMode } from '@angular/core';
                                 ~~~~~~~~~~~~~~~

../angular-node-express/src/main.ts:2:40 - error TS2307: Cannot find module '@angular/platform-browser-dynamic' or its corresponding type declarations.

2 import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
                                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

../angular-node-express/src/test.ts:4:28 - error TS2307: Cannot find module '@angular/core/testing' or its corresponding type declarations.

4 import { getTestBed } from '@angular/core/testing';
                             ~~~~~~~~~~~~~~~~~~~~~~~

../angular-node-express/src/test.ts:8:8 - error TS2307: Cannot find module '@angular/platform-browser-dynamic/testing' or its corresponding type declarations.

8 } from '@angular/platform-browser-dynamic/testing';
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

../book-it/e2e/src/app.e2e-spec.ts:2:34 - error TS2307: Cannot find module 'protractor' or its corresponding type declarations.

2 import { browser, logging } from 'protractor';
                                   ~~~~~~~~~~~~

../book-it/e2e/src/app.e2e-spec.ts:4:1 - error TS2582: Cannot find name 'describe'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha`.

4 describe('workspace-project App', () => {
  ~~~~~~~~

../book-it/e2e/src/app.e2e-spec.ts:7:3 - error TS2304: Cannot find name 'beforeEach'.

7   beforeEach(() => {
    ~~~~~~~~~~

../book-it/e2e/src/app.e2e-spec.ts:11:3 - error TS2582: Cannot find name 'it'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha`.

11   it('should display welcome message', () => {
     ~~

../book-it/e2e/src/app.e2e-spec.ts:13:5 - error TS2304: Cannot find name 'expect'.

13     expect(page.getTitleText()).toEqual('book-it app is running!');
       ~~~~~~

../book-it/e2e/src/app.e2e-spec.ts:16:3 - error TS2304: Cannot find name 'afterEach'.

16   afterEach(async () => {
     ~~~~~~~~~

../book-it/e2e/src/app.e2e-spec.ts:19:5 - error TS2304: Cannot find name 'expect'.

19     expect(logs).not.toContain(jasmine.objectContaining({
       ~~~~~~

../book-it/e2e/src/app.e2e-spec.ts:19:32 - error TS2304: Cannot find name 'jasmine'.

19     expect(logs).not.toContain(jasmine.objectContaining({
                                  ~~~~~~~

../book-it/e2e/src/app.po.ts:1:38 - error TS2307: Cannot find module 'protractor' or its corresponding type declarations.

1 import { browser, by, element } from 'protractor';
                                       ~~~~~~~~~~~~

../book-it/src/app/app.component.spec.ts:1:32 - error TS2307: Cannot find module '@angular/core/testing' or its corresponding type declarations.

1 import { TestBed, async } from '@angular/core/testing';
                                 ~~~~~~~~~~~~~~~~~~~~~~~

../book-it/src/app/app.component.spec.ts:4:1 - error TS2582: Cannot find name 'describe'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha`.

4 describe('AppComponent', () => {
  ~~~~~~~~

../book-it/src/app/app.component.spec.ts:5:3 - error TS2304: Cannot find name 'beforeEach'.

5   beforeEach(async(() => {
    ~~~~~~~~~~

../book-it/src/app/app.component.spec.ts:13:3 - error TS2582: Cannot find name 'it'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha`.

13   it('should create the app', () => {
     ~~

../book-it/src/app/app.component.spec.ts:16:5 - error TS2304: Cannot find name 'expect'.

16     expect(app).toBeTruthy();
       ~~~~~~

../book-it/src/app/app.component.spec.ts:19:3 - error TS2582: Cannot find name 'it'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha`.

19   it(`should have as title 'book-it'`, () => {
     ~~

../book-it/src/app/app.component.spec.ts:22:5 - error TS2304: Cannot find name 'expect'.

22     expect(app.title).toEqual('book-it');
       ~~~~~~

../book-it/src/app/app.component.spec.ts:25:3 - error TS2582: Cannot find name 'it'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha`.

25   it('should render title', () => {
     ~~

../book-it/src/app/app.component.spec.ts:29:5 - error TS2304: Cannot find name 'expect'.

29     expect(compiled.querySelector('.content span').textContent).toContain('book-it app is running!');
       ~~~~~~

../book-it/src/app/app.component.ts:1:27 - error TS2307: Cannot find module '@angular/core' or its corresponding type declarations.

1 import { Component } from '@angular/core';
                            ~~~~~~~~~~~~~~~

../book-it/src/app/app.component.ts:8:14 - error TS1219: 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.

8 export class AppComponent {
               ~~~~~~~~~~~~

../book-it/src/app/app.module.ts:1:31 - error TS2307: Cannot find module '@angular/platform-browser' or its corresponding type declarations.

1 import { BrowserModule } from '@angular/platform-browser';
                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~

../book-it/src/app/app.module.ts:2:26 - error TS2307: Cannot find module '@angular/core' or its corresponding type declarations.

2 import { NgModule } from '@angular/core';
                           ~~~~~~~~~~~~~~~

../book-it/src/app/app.module.ts:16:14 - error TS1219: 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.

16 export class AppModule { }
                ~~~~~~~~~

../book-it/src/main.ts:1:32 - error TS2307: Cannot find module '@angular/core' or its corresponding type declarations.

1 import { enableProdMode } from '@angular/core';
                                 ~~~~~~~~~~~~~~~

../book-it/src/main.ts:2:40 - error TS2307: Cannot find module '@angular/platform-browser-dynamic' or its corresponding type declarations.

2 import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
                                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

../book-it/src/test.ts:4:28 - error TS2307: Cannot find module '@angular/core/testing' or its corresponding type declarations.

4 import { getTestBed } from '@angular/core/testing';
                             ~~~~~~~~~~~~~~~~~~~~~~~

../book-it/src/test.ts:8:8 - error TS2307: Cannot find module '@angular/platform-browser-dynamic/testing' or its corresponding type declarations.

8 } from '@angular/platform-browser-dynamic/testing';
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Found 66 errors.
...