单身人士在自己的文件中时出现的问题

时间:2019-03-26 14:47:50

标签: typescript

因此,我正在使用单例并将其放入自己的文件中,但是我很难弄清楚如何访问它。我已经这样使用了:

import Single from './ts/Single';

let test = Single.getInstance();
test.doesItWork();

问题是它返回未定义。这是Single.ts文件:

export default class Single {
  private static instance:Single;

  private constructor(){}

  static getInstance(){
    if(!Single) Single.instance = new Single();
    return Single.instance;
  }

  doesItWork(){
    console.log('this worked');
  }
}

我必须将导出添加到单例中,否则不会将其添加到我的最终生产版本中。任何帮助将不胜感激

1 个答案:

答案 0 :(得分:0)

您需要检查ERROR: error loading package '': Encountered error while reading extension file 'swift/repositories.bzl': no such package '@build_bazel_rules_swift//swift': Traceback (most recent call last): File "C:/users/tensoruser/_bazel_tensoruser/37wcdhpe/external/bazel_tools/tools/build_defs/repo/git.bzl", line 164 _clone_or_update(ctx) File "C:/users/tensoruser/_bazel_tensoruser/37wcdhpe/external/bazel_tools/tools/build_defs/repo/git.bzl", line 74, in _clone_or_update fail(("error cloning %s:\n%s" % (ctx....))) error cloning build_bazel_rules_swift: + cd C:/users/tensoruser/_bazel_tensoruser/37wcdhpe/external + rm -rf C:/users/tensoruser/_bazel_tensoruser/37wcdhpe/external/build_bazel_rules_swift C:/users/tensoruser/_bazel_tensoruser/37wcdhpe/external/build_bazel_rules_swift /usr/bin/rm: missing operand Try '/usr/bin/rm --help' for more information. ERROR: error loading package '': Encountered error while reading extension file 'swift/repositories.bzl': no such package '@build_bazel_rules_swift//swift': Traceback (most recent call last): File "C:/users/tensoruser/_bazel_tensoruser/37wcdhpe/external/bazel_tools/tools/build_defs/repo/git.bzl", line 164 _clone_or_update(ctx) File "C:/users/tensoruser/_bazel_tensoruser/37wcdhpe/external/bazel_tools/tools/build_defs/repo/git.bzl", line 74, in _clone_or_update fail(("error cloning %s:\n%s" % (ctx....))) error cloning build_bazel_rules_swift: + cd C:/users/tensoruser/_bazel_tensoruser/37wcdhpe/external + rm -rf C:/users/tensoruser/_bazel_tensoruser/37wcdhpe/external/build_bazel_rules_swift C:/users/tensoruser/_bazel_tensoruser/37wcdhpe/external/build_bazel_rules_swift /usr/bin/rm: missing operand Try '/usr/bin/rm --help' for more information. INFO: Elapsed time: 0.680s INFO: 0 processes. FAILED: Build did NOT complete successfully (0 packages loaded) Fetching @build_bazel_rules_swift; Cloning tags/0.6.0 of https://github.com/bazelbuild/rules_swift.git ,而不仅仅是Single.instance(之所以定义,是因为它是类的名称,所以总是被检查):

Single