Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infer method argument types from interface. #26806

Closed
sinclairzx81 opened this issue Aug 31, 2018 · 2 comments
Closed

Infer method argument types from interface. #26806

sinclairzx81 opened this issue Aug 31, 2018 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@sinclairzx81
Copy link

Hi,

This has likely been asked before, and suspect there has probably been some consensus reached on the following. But curious with respect to the following implementation that seems to allow for breaking issues when not compiling in strict and Parameter 'x' implicitly has an 'any' type errors when compiling in strict when the type of x should be obvious.

interface IFoo {
    add(a: number, b: number): number
}
// class satisfies interface (non-strict)
class Foo implements IFoo {
   // can't `a` and `b` be inferred to be of type `number` ? 
   public add(a, b) {
        return a + b
    }
}

const foo = new Foo()
foo.add("hello", "world") // allowed (non-strict)

Are there any future plans to perhaps have TS statically resolve the arguments a and b when implementing from an interface in this way?

Many Thanks

@mattmccutchen
Copy link
Contributor

Duplicate of #23911.

@ahejlsberg ahejlsberg added the Duplicate An existing issue was already created label Aug 31, 2018
@sinclairzx81
Copy link
Author

@mattmccutchen thanks will track there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants