Closed
Description
Bug Report
π Search Terms
2556, tuple, union
π Version & Regression Information
n/a
β― Playground Link
Playground link with relevant code
π» Code
class Test {
one(s: string): void {s}
two(n: number): boolean {return n > 100}
ten(k: CryptoKey, w: Window): Document {k; return w.document}
}
const test = new Test()
export function run<Name extends keyof Test, Args extends Parameters<Test[Name]>>(name: Name, ...args: Args): void {
const fn = test[name]
fn(...args)
}
run('one', '')
run('two', 123)
run('ten', null, window)
π Actual behavior
TypeScript shows an error about the spread argument.
I've seen a bunch of similar issues, however I left unsatisfied with them. My specific concerns are these:
- Okay, so how do I create a wrapper function that preserves the static analysis?
- apply doesn't work as well, with a different error.
- Despite the error, TS seems to actually understand me and check the arguments of the wrapped functions, in particular:
- I can't call
run('five')
- I can't call
run('one')
- I can't call
run('one', 123)
- I can't call
run('ten', null, window)
as demonstrated in the last line
- TS doesn't provide any facilities to ignore this particular error that I know is irrelevant to me.
I'm left with no options, and I think this deserves an issue.
π Expected behavior
TypeScript doesn't show an error.
Metadata
Metadata
Assignees
Labels
No labels