首页 > 解决方案 > 打字稿:呈现自定义脚本标记引发错误 TS1005:“}”预期

问题描述

我有一个类MyScriptTag.tsx,我打算在其中呈现对主布局中包含的服务库的调用。这是它的样子:

import React from 'react';
import * as Radium from 'radium';
import { getUser } from '../actions/user';


const MyScriptTag = () => {
  return (
    <script>
      window['ExtLibrary'] = window['ExtLibrary'] || { _queue: [], Push: function (o, p) {this._queue.push({ type: o, data: p }); } };
      ExtLibrary.Push('User', {
        eMail: getUser().email
      });
    </script>
  );
};

const Component = Radium(MyScriptTag);
export default Component;

MainLayout.tsx它通过以下方式包含在一个类中:

class MainLayout extends React.Component<any, any> {
  render() {
    const { isLoggedIn, isLoggingIn } = this.props;

    return (
      <div>
        <section style={[styles.base]}>
          ...
          <MyScriptTag />
        </section>
      </div>
     )
   }
 }

代码未编译,这是我收到的错误消息:

error TS1005: '}' expected.

可能是新事物,因为我以前没有使用过打字稿。但我找不到解决方法,谷歌搜索也无济于事。

标签: angularjsreactjstypescript

解决方案


你错过了你}的结尾MainLayout.tsx,要关闭class


推荐阅读