Skip to content

Try enforcing contextual type of array literal elements #19541

Open
@RyanCavanaugh

Description

Part of #19236

Code

const s1: string[] = ["x", 3, null as any];
const s2: string[] = ["x", 3];

Expected behavior:

  • s1 should be an error
  • s2 should have an error span on 3

Actual behavior:

  • s1 is not an error
  • s2 has an error span on s2, which makes it impossible to figure out which element is wrong

Hypothesis: When checking a contextually-typed array literal, if an element type isn't assignable to the contextual type, issue an error on that element and return unknownType

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Breaking ChangeWould introduce errors in existing codeCommittedThe team has roadmapped this issueSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions