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

No typecheck errors on optional object method param #16247

Closed
giuseppelt opened this issue Jun 4, 2017 · 2 comments
Closed

No typecheck errors on optional object method param #16247

giuseppelt opened this issue Jun 4, 2017 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@giuseppelt
Copy link

TypeScript Version: 2.3.4

Code

type MethodOptions = {
    opt1?: string
    opt2?: number
}
class Test {
    method(options?: MethodOptions) {
    }
}

var test = new Test();
test.method("ciao");  //there should be an error here
test.method(1); // idem
test.method([]); // idem

directly on playground

Expected behavior:
Type checking errors

Actual behavior:
No errors

@ikatyang
Copy link
Contributor

ikatyang commented Jun 4, 2017

In my opinion, MethodOptions is considered to be one of these types:

  • {}
  • {opt1: string}
  • {opt2: number}
  • {opt1: string, opt2: number}

So "ciao" | 1 | [] is a valid MethodOptions, since they match the type of {}.

@jwbay
Copy link
Contributor

jwbay commented Jun 4, 2017

Duplicate of #7485, fixed by #16047

@mhegazy mhegazy added the Duplicate An existing issue was already created label Jun 4, 2017
@mhegazy mhegazy closed this as completed Jun 4, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants