microsoft / microsoft/TypeScript

`keyof Readonly<string[]>` different from `keyof Readonly<T>` where T is string[]

Open
#60,231 1 comment 0 reactions 1 assignee View on GitHub

@ahejlsberg is already working on this.

Since Oct 16, 2024.

Needs Investigation
Dominant language
Go
Stars
111k
Forks
14.4k
Avg merge
1d 19h
Merged PRs (30d)
117

Description

🔎 Search Terms

keyof Readonly array

🕗 Version & Regression Information

Latest to date

⏯ Playground Link

https://www.typescriptlang.org/play/?#code/C4TwDgpgBAKgjFAvFAShAhgEwPYDsA2IAPAM7ABOAlrgOYDaAugHwDcUA9O1ORjgSFDJVajALAAoUJFQJkAawghsAM1hw2nKAqWqeWPIUEVq9BhIlToAaUUB5ZWn38iMJki2KVqXgeKuWFuDQKABM7jYg9o58hKTGIswaXIAy5B46RsKmEkA

💻 Code
type T1 = Readonly<string[]>; // readonly string[]
type R1 = keyof T1; // keyof readonly string[]

type KeyOfReadonly<T> = keyof Readonly<T>;
type R2 = KeyOfReadonly<string[]>; // ❌ keyof string[]
🙁 Actual behavior

doesn't work

🙂 Expected behavior

works

Additional information about the issue

What can I say, I really hope this is not the intended behavior.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.