React ASP.NET Core-js'类型断言表达式'只能在.ts文件中使用

时间:2019-04-25 15:04:16

标签: reactjs typescript asp.net-core

我刚刚在Visual Studio 2017中创建了一个新的React应用程序(不是VSCode,因为关于此错误的许多其他文章似乎都在使用),并且它设置了以下内容的默认文件内容:

package.json

{
  "name": "React",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "bootstrap": "^3.3.7",
    "react": "^16.0.0",
    "react-bootstrap": "^0.31.5",
    "react-dom": "^16.0.0",
    "react-router-bootstrap": "^0.24.4",
    "react-router-dom": "^4.2.2",
    "react-scripts": "1.0.17",
    "rimraf": "^2.6.2"
  },
  "scripts": {
    "start": "rimraf ./build && react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  }
}

appsettings.json

{
  "Logging": {
    "LogLevel": {
      "Default": "Warning"
    }
  },
  "AllowedHosts": "*"
}

App.js

import React, { Component } from 'react';
import { Route } from 'react-router';
import { Layout } from './components/Layout';
import { Home } from './components/Home';
import { FetchData } from './components/FetchData';
import { Counter } from './components/Counter';

export default class App extends Component {
  displayName = App.name

  render() {
    return (
      <Layout>
        <Route exact path='/' component={Home} />
        <Route path='/counter' component={Counter} />
            <Route path='/fetchdata' component={FetchData} />
      </Layout>
    );
  }
}

我正在尝试按照教程添加新组件,但是当我添加以下组件时,它抱怨“(JS)'类型断言表达式'只能在.ts文件中使用”错误消息:

Error Message

我发现了很多其他的帖子,它们说要添加以下代码,但已将其添加到appsettings.json文件中,但没有任何效果:

"javascript.validate.enable": false

围绕该主题的大多数帖子似乎也在使用VSCode,因此不确定是否可以使我在VS2017上有所作为?关于我需要更改以使其能够编译和运行的任何想法?

0 个答案:

没有答案