【发布时间】:2018-12-30 01:13:19
【问题描述】:
我在 react 中使用 typescript 并且下面的文件抛出了很多错误,我不知道为什么(它作为 js 工作),但我怀疑这里与传播运算符有关?
import React from 'react'
import { Subscribe } from 'unstated'
const getStoreAsProps = (storeArr) => {
const storeProps = {}
storeArr.map((value) => (storeProps[value.name] = value))
return storeProps
}
const withStore = (...args) => (Element) => () => (
<Subscribe to={[...args]}>{(...args) => <Element {...getStoreAsProps(args)} />}</Subscribe>
)
export default withStore
tsc 抛出的错误是
workspace/app/store/index.ts:11:14 - 错误 TS1005: '>' 预期。
11 {(...args) => } ~~
workspace/app/store/index.ts:11:16 - 错误 TS1005: ')' 预期。
11 {(...args) => } ~
workspace/app/store/index.ts:11:19 - 错误 TS1109:表达式 预计。
11 {(...args) => } ~~~
workspace/app/store/index.ts:11:26 - 错误 TS1005: ',' 预期。
11 {(...args) => } ~
workspace/app/store/index.ts:11:30 - 错误 TS1136:属性分配 预计。
11 {(...args) => } ~
workspace/app/store/index.ts:11:40 - 错误 TS1005: ';'预计。
11 {(...args) => } ~~
workspace/app/store/index.ts:11:52 - 错误 TS1005: '>' 预期。
11 {(...args) => } ~
workspace/app/store/index.ts:11:80 - 错误 TS1109:表达式 预计。
11 {(...args) => } ~
workspace/app/store/index.ts:11:81 - 错误 TS1109:表达式 预计。
11 {(...args) => } ~
workspace/app/store/index.ts:11:83 - 错误 TS1110:预期类型。
11 {(...args) => } ~
workspace/app/store/index.ts:11:84 - 错误 TS1161:未终止 正则表达式字面量。
11 {(...args) => }
workspace/app/store/index.ts:12:1 - 错误 TS1128:声明或 预期的声明。
12) ~
如果有帮助,语法高亮也会在那里中断
【问题讨论】:
-
试试
import * as React from "react";
标签: javascript reactjs typescript ecmascript-6