lamada

ts 类型推导问题

  •  
  •   lamada · May 27, 2020 · 3584 views
    This topic created in 2206 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
        1
    SilentDepth  
       May 27, 2020
    Type-only imports and exports
    lamada
        3
    lamada  
    OP
       May 27, 2020
    @SilentDepth nb, 现在已经这么高级了
    lamada
        4
    lamada  
    OP
       May 27, 2020
    @SilentDepth 就是 eslint 好像还没支持,有点蛋疼
    shunf4
        5
    shunf4  
       May 28, 2020 via Android
    @lamada 支持了吧,我一直这么搞
    lamada
        6
    lamada  
    OP
       May 29, 2020
    @shunf4 可能我 ts 版本太低了,更新了好像可以了
    wi
        7
    wi  
       May 31, 2020
    用过 vue 的 vuex 吗
    wi
        8
    wi  
       May 31, 2020
    vuex 的情况类似
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3834 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 38ms · UTC 04:36 · PVG 12:36 · LAX 21:36 · JFK 00:36
    ♥ Do have faith in what you're doing.