Skip to content

Variables referenced indirectly in their initializers are resolved to 'any' #522

Closed
@mhegazy

Description

@mhegazy

The compiler already behaves as per spec, and variables referenced directly or indirectly in their initializers resolve to any. The previous implementation did not just assign them to any, by attempted to go deeper one level, here are some examples;

var a = { f: a };

Now:

a : any

Was:

a: { f: any };

var fibonacci = _.memoize(n =>  n < 2 ? n : fibonacci(n - 1) + fibonacci(n - 2); } );

Now:

fibonacci : any

Was:

fibonacci : (n: any) => any

var n1 = n1++;

Now:

n1 : any

Was:

n1 : number

see tests:

  • tests/cases/compiler/recursiveObjectLiteral.ts
  • tests/cases/compiler/underscoreTest1_underscoreTests.ts
  • tests/cases/conformance/statements/VariableStatements/recursiveInitializer.ts

Metadata

Metadata

Assignees

No one assigned

    Labels

    Breaking ChangeWould introduce errors in existing codeFixedA PR has been merged for this issueSpecIssues related to the TypeScript language specification

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions