Skip to content

Should not widen in type argument inference #1436

Closed
@JsonFreeman

Description

@JsonFreeman

Compile the following using noImplicitAny:

function foo<T>(x: T): T { return x }

interface I {
    x: string;
}

var i: I = foo({ x: null }); // Error
var s: string = f(null); // No error

Neither of these should be errors. According to the spec, both of these should widen, but in #531 @DanielRosenwasser and I explain why these should not widen.

The noImplicitAny error resulting from widening is a breaking change from 1.0, and it broke a customer.

Metadata

Metadata

Assignees

Labels

Breaking ChangeWould introduce errors in existing codeSpecIssues related to the TypeScript language specification

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions