@parcel/变形金刚-通天塔:意外令牌,预期";"



我正在尝试学习如何在 React 中使用 Typescript。我已按如下方式声明了应用程序组件:

import * as React from "react";
import { Component } from "react";
type AppState = {
apiResponse: string;
};
export default class App extends Component<{}, AppState> {
testApi() {
const url = "http://localhost:9000/testApi";
const body = {};
fetch(url)
.then((res) => res.text())
.then((data) => this.setState({ apiResponse: data }));
}
componentWillMount() {
this.testApi();
}
render() {
return (
<>
<h1>{this.state.apiResponse}</h1>
</>
);
}
}

我收到以下错误:

SyntaxError: Unexpected token, expected ";" (4:5)
3 | 
> 4 | type AppState = {
>   |     ^
5 |   apiResponse: string;
6 | };

我对语法的理解有问题还是我的包裹依赖项有问题?

所以事实证明,包裹依赖性有问题。我最初用nano-react-app创建了 React 应用程序,只是用create-react-app重做了它。现在一切正常。

最新更新