lamada

ts 类型推导问题

  •  
  •   lamada · May 27, 2020 · 3998 views
    This topic created in 2355 days ago, the information mentioned may be changed or developed.

    我有一个 system 管理了很多 model,有一些 model 可能会用到其他 model 的方法,有什么办法可以在一个 model 在不引用其他 model 的情况下获得类型推导?除了单独编写 d.ts

    // 这里运行是 a,b 可能都是异步加载的,打包时相互不引用
    
    // a.ts
    class A {
    	bar (name: string): void {}
    }
    
    
    // b.ts
    class B {
    	foo () {
        	// root 指代的是 system,通过 system 获取其他 model 。这里想获得 bar 的类型推导
        	this.root.a.bar('hello')
        }
    }
    
    8 replies  •  2020-05-31 22:39:39 +08:00
    SilentDepth
    SilentDepth
    May 27, 2020
    1
    Type-only imports and exports
    lamada
    lamada
    OP
    May 27, 2020
    3
    @SilentDepth nb, 现在已经这么高级了
    lamada
    lamada
    OP
    May 27, 2020
    4
    @SilentDepth 就是 eslint 好像还没支持,有点蛋疼
    shunf4
    shunf4
    May 28, 2020 via Android
    5
    @lamada 支持了吧,我一直这么搞
    lamada
    lamada
    OP
    May 29, 2020
    6
    @shunf4 可能我 ts 版本太低了,更新了好像可以了
    wi
    wi
    May 31, 2020
    7
    用过 vue 的 vuex 吗
    wi
    wi
    May 31, 2020
    8
    vuex 的情况类似
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1907 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 07:39 · PVG 15:39 · LAX 23:39 · JFK 02:39
    ♥ Do have faith in what you're doing.