打字稿模块和导入 - 参考? [英] Typescript modules and importing - references?

查看:49
本文介绍了打字稿模块和导入 - 参考?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

模型/对象/A.ts

module App.Models.Objects
{
    export class A
    {}
}

模型/摘要/ISomethingElse.ts

module App.Models.Abstracts
{
    export interface ISomethingElse
    {
        A: A;
    }
}

如何使用 ISomethingElse.ts 文件中的 App.Models.Objects 模块?

How do i use the module App.Models.Objects from the ISomethingElse.ts file?

我试过引用:

/// <reference path="../Objects/A.ts" />

但是它仍然找不到A,因为它在模块中.我如何导入它?

But it still cannot find A because it's in the module. How do i import it?

我尝试导入:

/// <reference path="../Objects/A.ts" />
import A = require("App.Models.Objects");

但它仍然无法编译.

我做错了什么?

推荐答案

假设您没有使用为您处理引用的编辑器,那么您使用的相对引用路径是错误的.以下应该有效:

Assuming you're not using an editor that takes care of the references for you, the relative reference path you've used is wrong. The following should work:

/// <reference path="../objects/A.ts"/>
    
module App.Models.Abstracts
{
  export interface ISomethingElse
  {
    a: App.Models.Objects.A;
  }
}

这篇关于打字稿模块和导入 - 参考?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆