例如在 my-components-list.html 我有:
<my-component #first></my-component>
<my-component #second></my-component>
<my-component #third></my-component>
<input #forth/>
Run Code Online (Sandbox Code Playgroud)
我想在我的测试中得到它,例如:
it('test', () => {
const myComponent: HTMLElement = fixture.debugElement.query(By.someMethod('#first'));
const myInput: HTMLElement = fixture.debugElement.query(By.someMethod('#forth'));
}
Run Code Online (Sandbox Code Playgroud) 目前,TypeScript 允许声明动态泛型参数。
function bind<U extends any[]>(...args: U);
Run Code Online (Sandbox Code Playgroud)
但是如果我希望我的函数返回参数类型的并集怎么办?就像是:
function bind<U extends any[]>(...args: U): U1 | U2 | U3...;
Run Code Online (Sandbox Code Playgroud)
有没有办法做到这一点?