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

array types don't extend type with wider key type #47331

Closed
DetachHead opened this issue Jan 6, 2022 · 5 comments
Closed

array types don't extend type with wider key type #47331

DetachHead opened this issue Jan 6, 2022 · 5 comments
Labels
Not a Defect This behavior is one of several equally-correct options

Comments

@DetachHead
Copy link
Contributor

Bug Report

πŸ”Ž Search Terms

array record extends

πŸ•— Version & Regression Information

4.6.0-dev.20220105

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

type A = Record<number | string, unknown>
type B = Record<number, unknown>
type C = unknown[]

type Foo = B extends A ? true : false //true

type Bar = C extends B ? true : false //true

type Baz = C extends A ? true : false //false

πŸ™ Actual behavior

C doesn't extend A, even though it extends B which extends A

πŸ™‚ Expected behavior

C extends A

@RyanCavanaugh RyanCavanaugh added the Not a Defect This behavior is one of several equally-correct options label Jan 11, 2022
@RyanCavanaugh
Copy link
Member

Transitivity is not a property of assignability (this fact is easily demonstrated with optional properties, which is one way to reason about how index signatures should work).

@DetachHead
Copy link
Contributor Author

this fact is easily demonstrated with optional properties

could you show an example of this please

@RyanCavanaugh
Copy link
Member

{ a?: number } -> { } -> { a?: string }

@DetachHead
Copy link
Contributor Author

i see what you mean now. however in that example it's obvious { a?: number } doesn't extend { a?: string } but i'm having trouble wrapping my head around why unknown[] doesn't extend Record<number | string, unknown>

@github-actions
Copy link

github-actions bot commented Jun 8, 2023

This issue has been marked as 'Not a Defect' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jun 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Not a Defect This behavior is one of several equally-correct options
Projects
None yet
Development

No branches or pull requests

2 participants