简体   繁体   English

获取:错误 TS1128:预期的声明或语句。 在 ReactJS 和 TypeScript 应用程序中

[英]Getting: error TS1128: Declaration or statement expected. In ReactJS & TypeScript app

Here is my current code for the new component I created which is causing this error to be throw.这是我创建的新组件的当前代码,它导致抛出此错误。

Failed to compile.编译失败。

./src/components/Hello.tsx (5,1): error TS1128: Declaration or statement expected. ./src/components/Hello.tsx (5,1): 错误 TS1128: 需要声明或语句。

I've checked other answers and haven't found the actual issue yet.我已经检查了其他答案,但还没有找到实际问题。

// src/components/Hello.tsx

import * as React from 'react';

export Interface Props {
  name: string;
  enthusiasmLevel?: number;
}

function Hello({ name, enthusiasmLevel = 1 }: Props) {
  if (enthusiasmLevel <= 0) {
    throw new Error('You could be a little more enthusiastic. :D');
  }

  return (
    <div className="hello">
      <div className="greeting">
        Hello {name + getExclamationMarks(enthusiasmLevel)}
      </div>
    </div>
  );
}

export default Hello;

// helpers

function getExclamationMarks(numChars: number) {
  return Array(numChars + 1).join('!');
}

Change改变

export Interface Props {

to

export interface Props {

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 预期声明或声明。 ts(1128) - Declaration or statement expected. ts(1128) TS1128 'Declaration or statement expected' 文件末尾的错误不会 go 消失,即使代码看起来很好 - TS1128 'Declaration or statement expected' error at end of file that won't go away even though code seems fine 我正在尝试在 Javascript 中编写一个 discord 机器人,但它一直在说“预期的声明或声明。ts(1128)” - I'm trying to code a discord bot in Javascript but it keeps saying "Declaration or statement expected. ts(1128)" 如何修复 Discord.js 中的“Declaration or statement expected.ts(1128)”? - How do I fix "Declaration or statement expected. ts(1128)" in Discord.js? JavaScript 声明或声明预期.ts(1128) - JavaScript Declaration or statement expected.ts(1128) 我的 discord 机器人 on.setColor 上的声明或声明 expected.ts(1128) - Declaration or statement expected.ts(1128) on my discord bot on .setColor case 显示“预期的声明或声明”。 错误 - case shows 'declaration or statement expected.' error 打字稿错误TS1005:':'预期。使用Object.assign() - Typescript error TS1005: ':' expected. with Object.assign() TypeScript - 错误 TS1146:需要声明 - TypeScript - error TS1146: Declaration expected 打字稿错误TS1005:&#39;;&#39; 预期。 TS v1.8.10 - Typescript error TS1005: ';' expected. TS v1.8.10
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM