[英]Angular TS1003 Identifier expected on throw import statement, my error stems from the import of throw from 'rxjs'
I have this line of code我有这行代码
import { Observable, throw} from 'rxjs';
I'm getting the error identifier expected:我得到了预期的错误标识符:
ERROR in config/config.service.ts(3,22): error TS1003: Identifier expected.
config/config.service.ts(3,22) 中的错误:错误 TS1003:需要标识符。
It indicated the error is stemming from that line/ position 22, which is the start of the throw
word.它表明错误源于该行/位置 22,这是
throw
字的开始。
What do i need to do in order to resolve this issue?我需要做什么才能解决这个问题? what do they mean by an identifier?
他们所说的标识符是什么意思?
I came across this looking to resolve the same error, but with a different cause.我遇到了这个,希望解决相同的错误,但原因不同。 In case anyone else is having the same, my issue was that I converted some dot-notation references to string notation, but forgot to get rid of the dots!
如果其他人有同样的情况,我的问题是我将一些点符号引用转换为字符串符号,但忘记去掉点!
Example:例子:
// Started with ...
const variableName = someObject.dynamicPropertyName;
// Was changed to ...
const variableName = someObject.['dynamicPropertyName'];
// Instead of ...
const variableName = someObject['dynamicPropertyName'];
In my case, it was just a bad find-replace-issue.就我而言,这只是一个糟糕的查找替换问题。 But I imagine that someone may run into this in other situations as well.
但我想有人也可能在其他情况下遇到这种情况。
First, identifiers are the names that you give to your variables, functions, etc. It's the official term for them and carries with it the rules for which characters are valid within them.首先,标识符是您为变量、函数等提供的名称。它是它们的官方术语,并带有其中字符有效的规则。
In most cases, though, an identifier cannot be the same name as a reserved word – the names used by the language itself, such as control structures ( if
, for
, etc.).但是,在大多数情况下,标识符不能与保留字同名——语言本身使用的名称,例如控制结构(
if
、 for
等)。
let for;
// SyntaxError at `for`
throw
is one such reserved word, which represents a statement for raising custom errors, and cannot be used as a variable defined by import
. throw
是一个这样的保留字,它表示引发自定义错误的语句,不能用作import
定义的变量。
To get around this, you can specify your own name/identifier (alias) for rx.js' throw
with as
.要解决此问题,您可以使用
as
为 rx.js 的throw
指定自己的名称/标识符(别名)。
const { Observable, throw as rxThrow } from 'rxjs';
throw
is a reserved word, try: throw
是保留字,请尝试:
import { Observable } from 'rxjs';
import 'rxjs/add/observable/throw';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.