Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeScript to infer type arguments in interface implementation class

Tags:

typescript

It will complain that type of arg is any

interface Foo { 
  foo(arg: string): void 
}

class FooImpl implements Foo {
  foo(arg) { console.log(arg) }
}

I can of course specify that it's string but it's repetitive.

Maybe there's a way to tune TypeScript to make it infer that it's string automatically?

like image 322
Alex Craft Avatar asked Dec 31 '17 00:12

Alex Craft


1 Answers

Maybe there's a way to tune TypeScript to make it infer that it's string automatically

No. Here is the relevant TypeScript issue with reasons why its not there: https://github.com/Microsoft/TypeScript/issues/1373

like image 79
basarat Avatar answered Sep 25 '22 14:09

basarat