打字稿错误';'预期的。 'EventNameString' 仅指一种类型,但在此处用作值
Posted
技术标签:
【中文标题】打字稿错误\';\'预期的。 \'EventNameString\' 仅指一种类型,但在此处用作值【英文标题】:Typescript Error ';' expected. 'EventNameString' only refers to a type, but is being used as a value here打字稿错误';'预期的。 'EventNameString' 仅指一种类型,但在此处用作值 【发布时间】:2020-04-15 21:05:51 【问题描述】:我正在尝试将 firebase 电话身份验证添加到一个旧的 ionic 项目中,并遵循了几个教程。我设法实现它,但每次我做ionic serve -l
时都会出现这个错误:
但是我注意到,如果我在ionic serve -l
之后评论了app.modules.ts
中的其中一行,错误就会消失:
import AngularFireModule from "@angular/fire";
import AngularFireAuth from "@angular/fire/auth";
由于错误在 node-modules 文件夹中,我尝试多次删除它,甚至在其他 PC 上尝试过,在这里和那里遵循了一些答案,但我无法解决它。
错误文本:
Typescript Error
';' expected.
gtagName?: string;
/** Sets custom name for `dataLayer` array used by gtag. */
dataLayerName?: string;
Typescript Error
'EventNameString' only refers to a type, but is being used as a value here.
/** Sets custom name for `dataLayer` array used by gtag. */
dataLayerName?: string;
Typescript Error
'never' only refers to a type, but is being used as a value here.
/** Sets custom name for `dataLayer` array used by gtag. */
dataLayerName?: string;
Typescript Error
Cannot find name 'T'.
/** Sets custom name for `dataLayer` array used by gtag. */
dataLayerName?: string;
离子信息:
Ionic Framework: ^3.9.8
Ionic App Scripts: 3.2.4
Angular Core: ^5.2.7
Angular Compiler CLI: ^5.2.7
Node: 12.13.1
OS Platform: Windows 10
Navigator Platform: Win32
User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (Khtml, like Gecko) Chrome/79.0.3945.88 Safari/537.36
app.modules.ts
导入依赖:
import ErrorHandler, Injectable, Injector, NgModule from "@angular/core";
import IonicApp, IonicErrorHandler, IonicModule from "ionic-angular";
import BrowserModule from "@angular/platform-browser";
import HttpModule from "@angular/http";
import HttpClient, HttpClientModule from "@angular/common/http";
import Geolocation from "@ionic-native/geolocation";
import NativeGeocoder from "@ionic-native/native-geocoder";
import MyApp from "./app.component";
import TabsPage from "../pages/tabs/tabs";
import Loading from "../pages/loading/loading";
import Welcome from "../pages/welcome/welcome";
import GeoPage from "../pages/geo/geo";
import IonicStorageModule from "@ionic/storage";
import StatusBar from "@ionic-native/status-bar";
import SplashScreen from "@ionic-native/splash-screen";
import APIService from "../services/api_service";
import CartService from "../services/cart_service";
import PushService from "../services/push_service";
import UtilService from "../services/util_service";
import OrderHistoryService from "../services/order_history_service";
import TranslateLoader, TranslateModule from "@ngx-translate/core";
import TranslateHttpLoader from "@ngx-translate/http-loader";
import RestaurantsPageModule from "../pages/catalog/restaurants/restaurants.module";
import GeoPageModule from "../pages/geo/geo.module";
import AngularFireModule from "@angular/fire";
import AngularFireAuth from "@angular/fire/auth";
import firebaseConfig from "../config";
import LoginPage from "../pages/personal/login/login";
import AuthService from "../services/auth.service";
import NgxErrorsModule from '@ultimate/ngxerrors';
【问题讨论】:
我会尝试清理 node_modules 和它的缓存并重新安装它。.. @nircraft 我这样做了很多次,甚至在新设置的 PC 上尝试过:git clone
'ed 然后npm install
。在我开始实现 firebase 功能之前,一切都很好。这个问题真的很奇怪
【参考方案1】:
主要的是,当您尝试将类型设置为EventNameString
时,您必须使用=
而不是:
和EventNameString
。这就是为什么您收到错误“EventNameString”仅指一种类型,但在此处用作值的原因。
如我所见,这些主要是语法错误。正如@nircraft 建议的那样,您应该尝试清理node_modules
,它是cache
,然后重新安装。
【讨论】:
但是,如果您查看此error screenshot,则错误指向node-modules
文件夹中该文件的同一行,我没有对其进行修改。另外,我确实清理了node-moduels
,它是cache
多次,结果相同。以上是关于打字稿错误';'预期的。 'EventNameString' 仅指一种类型,但在此处用作值的主要内容,如果未能解决你的问题,请参考以下文章