Skip to content

Allow users to customize the variance of built-in ArrayΒ #52621

@devanshj

Description

@devanshj

Bug Report

πŸ”Ž Search Terms

Array covariance hardcoded?, Array invariance, --noLib

πŸ•— Version & Regression Information

Tested with 4.9.5

⏯ Playground Link

https://tsplay.dev/WPzdYN

πŸ’» Code

// @noLib: true

interface Array<T>
  { [i: number]: T | undefined
  , push: (t: T) => number
  }

interface _Array<T>
  { [i: number]: T | undefined
  , push: (t: T) => number
  }

declare let as: Array<"a">
declare let abs: Array<"a" | "b">
abs = as

declare let _as: _Array<"a">
declare let _abs: _Array<"a" | "b">
_abs = _as

πŸ™ Actual behavior

The assignment abs = as compiles.

πŸ™‚ Expected behavior

The assignment abs = as should not compile, just like the assignment _abs = _as does not compile.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy