TS 中返回参数类型如何做三元判断?

有一个 getList 的函数,总共有两种type。每种 type 返回不同的list。
图上我知道写的不对,但是不知道咋写。求指教
(PS:用的web sql,老代码改造ts)
image.png

简单奉上代码:

    async getDBDate() {
        let tabList = (await this.getList('TABS'));
        let infoList = (await this.getList('INFOS'));
        if (tabList.length === 0) {
            // 一些其他操作
        }
         
    }

    async getList<K,V = 'TABS' | 'INFOS'>(type: K extends keyof V) {
        return (await this.executeSql(`SELECT * FROM ${type}`)) as K extends 'TABS' ? T.TabList[] : T.InfoList[];
    }
阅读 1.7k
1 个回答