Skip to content

Use 'never' type for empty array literals - #8907

Closed
Anders Hejlsberg (ahejlsberg) wants to merge 2 commits into
masterfrom
neverTypeWidening
Closed

Use 'never' type for empty array literals#8907
Anders Hejlsberg (ahejlsberg) wants to merge 2 commits into
masterfrom
neverTypeWidening

Conversation

@ahejlsberg

Copy link
Copy Markdown
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 --strictNullChecksfunctionconcat<T>(xs: T[],ys: T[]): T[]{return[...xs, ...ys];}consty=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
Copy Markdown
Contributor

👍

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");

@DanielRosenwasserDaniel Rosenwasser (DanielRosenwasser)Jun 1, 2016

Copy link
Copy Markdown
Member

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 wideningnever implies over an unwidened never and why you need it.

@ahejlsberg

Copy link
Copy Markdown
MemberAuthor

Superceded by #8944.

@mhegazy
Mohamed Hegazy (mhegazy) deleted the neverTypeWidening branch June 3, 2016 23:21
@microsoftMicrosoft (microsoft) locked and limited conversation to collaborators Jun 19, 2018
Sign up for freeto 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

@ahejlsberg@mhegazy@DanielRosenwasser@msftclas