Skip to content

Conversation

@ahejlsberg
Copy link
Member

This PR introduces a widening form of the never type that we use for empty array literals in --strictNullChecks mode. This fixes the following issue reported in #8878:

// Compile with --strictNullChecks
function concat<T>(xs: T[], ys: T[]): T[] {
    return [...xs, ...ys];
}
const y = concat([], ["a"]);  // Should be type string[]

Before this fix the inferred type above was (string | undefined)[] because we were using type undefined[] for empty array literals, and undefined isn't a bottom type in strict null checking mode.

@mhegazy
Copy link
Contributor

mhegazy commented Jun 1, 2016

👍

const emptyArrayElementType = createIntrinsicType(TypeFlags.Undefined | TypeFlags.ContainsUndefinedOrNull, "undefined");
const unknownType = createIntrinsicType(TypeFlags.Any, "unknown");
const neverType = createIntrinsicType(TypeFlags.Never, "never");
const wideningNeverType = createIntrinsicType(TypeFlags.Never | TypeFlags.ContainsWideningType, "never");
Copy link
Member

@DanielRosenwasser DanielRosenwasser Jun 1, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leave a comment on what a widening never implies over an unwidened never and why you need it.

@ahejlsberg
Copy link
Member Author

Superceded by #8944.

@ahejlsberg ahejlsberg closed this Jun 3, 2016
@mhegazy mhegazy deleted the neverTypeWidening branch June 3, 2016 23:21
@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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants