Skip to content

Case that infering type for parameters works for 3.3.0 but error in 3.4.0 #30840

Closed
@TerenceZ

Description

@TerenceZ

TypeScript Version: 3.4.0-dev.201xxxxx

Search Terms:

3.4.0 regression
parameter type infer

Code

// with compilerOptions.noImplicitAny=true in tsconfig.json
export function test<S>(options: { partial: Partial<S> | undefined }) {
  const fn: any = function (state = options.partial, action_: any) {
    return state
  }
  return fn
}

The related tsconfig.json

{
  "compilerOptions": {
    "target": "es5",
    "lib": ["dom", "dom.iterable", "esnext"],
    "noImplicitAny": true,
    "noImplicitReturns": true,
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "preserve"
  },
  "include": ["src"]
}

Expected behavior:
No error. It's worth noting that it works in 3.3.4.

Actual behavior:

With the tsc command line, it outputs the following errors:

error TS7006: Parameter 'state' implicitly has an 'any' type.

25   const fn: any = function(state = options.partial, action_: any) {

Playground Link:

Related Issues:


The code works in 3.3.4 with no errors, but after upgrading to 3.4.0, the tsc complains that the parameter has 'any' type when the LHS fn is of any type. If I replace fn: any = with fn =, it works for 3.4.0.

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