daguaochengtang
V2EX  ›  问与答

typescript 中如何在全局变量声明文件中引用另一个声明文件中的导出类型?

  •  
  •   daguaochengtang · Aug 21, 2023 · 1082 views
    This topic created in 992 days ago, the information mentioned may be changed or developed.
    场景:
    我在项目中编写了一个全局变量声明文件 service.d.ts ,内容如下:

    ```typescript
    /// <reference types="axios" />

    declare namespace AppService {
    type BaseAxiosRes = AxiosResponse // AxiosResponse 显示的类型是 any
    }
    ```
    我想在全局 namespace 中引用 axios 的 AxiosResponse 类型,我使用了三斜线指令引入了 axios ,但是下面的 AxiosResponse 类型显示为 any 。

    图片贴在下面,没有上传图床,直接用的 segmentfault 的图片,v 站如果加载不了就复制链接看吧
    ![]( https://segmentfault.com/img/bVc9lrS)
    ![]( https://segmentfault.com/img/bVc9lrX)
    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3034 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 42ms · UTC 13:58 · PVG 21:58 · LAX 06:58 · JFK 09:58
    ♥ Do have faith in what you're doing.