简体   繁体   English

Angular TS1003 标识符预期在 throw import 语句中,我的错误源于从 'rxjs' 导入 throw

[英]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.).但是,在大多数情况下,标识符不能与保留字同名——语言本身使用的名称,例如控制结构( iffor等)。

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.

相关问题 如何配置TypeScript对不正确的导入语句抛出错误/警告? - How to configure TypeScript to throw an error/warning for incorrect import statement? 导入语句中的“语法错误:意外的标识符”? - "SyntaxError: Unexpected identifier" from import statement? 从.ts导入变量到.scss angular - Import variables from .ts into .scss angular 当导出文件中未定义导出属性时,import语句不会引发任何错误 - import statement doesn't throw any error when a exported property is not defined in the export file 在 rxjs Observable 中抛出错误 - throw error inside rxjs Observable 从ts文件中的js文件导入功能(角度2) - Import function from js file in a ts file (angular 2) “throw”语句的意外“未定义”输出 - Unexpected 'undefined' output from 'throw' statement 浏览器抛出导出/导入关键字的错误,甚至安装了webpack和babel - browser throw error of export/import keyword even webpack and babel is installed 为什么要用角度的方法从“ some.component.ts”中使用“ import {SomeComponent}”,而不是从“ some.component.ts”中使用“ import SomeComponent”? - Why angular use `import { SomeComponent } from 'some.component.ts'` instead of `import SomeComponent from 'some.component.ts'` Angular 2 Promise抛出错误 - Angular 2 Promise throw error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM