Skip to content

Incorrect type inferrence for default-initialized parameters and noImplicitAny #36052

Closed
@dave-hart

Description

@dave-hart

Having a default initialized parameter in a function declaration passed to a function incorrectly asserts that the parameter is an any type

TypeScript Version:
3.7.4 (also reproduced on Nightly)
I recently upgraded from Typescript 3.5.2 to 3.7.3. The code below was fine with ts 3.5.2

Search Terms:
default parameter noImplicitAny
Code

function execute(script: string | Function): Promise<string> {
  return new Promise((resolve, reject) => {
    if (typeof script === 'string') {
      reject('rejecting promise');
    }
    resolve('resolving promise');
  });
}

export function executeSomething() {
  return execute((root: HTMLElement, debug = true) => {
    if (debug) {
      root.innerHTML = '';
    }
  });
}

Expected behavior:
No Errors

Actual behavior:
I get an error for the debug = true statement. "TS7006: Parameter 'debug' implicitly has an 'any' type."

Playground Link:
Playground link

Related Issues:
None

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions