Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use 'never' type for empty array literals #8907

Closed
wants to merge 2 commits into from
Closed

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 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.

4 participants