Skip to content

Default parameters should subtract undefined from internal function signature #12726

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

Closed
blakeembrey opened this issue Dec 7, 2016 · 1 comment
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@blakeembrey
Copy link
Contributor

TypeScript Version: 2.1.4

Code

function f (offset: number) {}

let x = (offset = 0) => {
  f(offset)
}

x = function (offset = 0) {
  f(offset)
}
{
  "compilerOptions": {
    "target": "es5",
    "outDir": "dist",
    "module": "commonjs",
    "noImplicitAny": true,
    "strictNullChecks": true
  }
}

Expected behavior: No error.

Actual behavior:

index.ts(8,5): error TS2345: Argument of type 'number | undefined' is not assignable to parameter of type 'number'.
  Type 'undefined' is not assignable to type 'number'.

I believe this has actually been an issue in previous releases, but 2.1 has made it apparent in other argument positions. I just tested 2.0 and can reproduce the above sample, but it doesn't fail on 2.0 with (x: string, y = 0) whereas 2.1 does.

@mhegazy
Copy link
Contributor

mhegazy commented Dec 7, 2016

Looks like the flip side of #11900

@mhegazy mhegazy added the Bug A bug in TypeScript label Dec 7, 2016
@mhegazy mhegazy added this to the TypeScript 2.2 milestone Dec 7, 2016
@mhegazy mhegazy modified the milestones: TypeScript 2.2, TypeScript 2.3 Feb 2, 2017
@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Feb 13, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

3 participants