Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. Itย collects links to all the places you might be looking at while hunting down a tough bug.

And, if youโ€™re still stuck at the end, weโ€™re happy to hop on a call to see how we can help out.

Issue a better error message when trying to use a modifier outside of a mapped type

See original GitHub issue

TypeScript Version: 3.4.0-dev.201xxxxx

Search Terms:


export type ITSReadonlyToWriteableArray<T extends readonly any[]> =  Omit<T, keyof any[]> & 
 ITSUnpackedArrayLike<T>[] & {
	-readonly [P in number | 'length']: T[P]
export type ITSWriteableArray<T extends readonly any[]> = Omit<T, 'length' | number> & {
	-readonly length: number
// => here is error

Expected behavior:

no error, more better error message

Actual behavior:

Error:(96, 12) TS1005: โ€˜[โ€™ expected.

and a small ask (donโ€™t need care this Quesion)

Q: how to list all readonly key

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

jcalzcommented, May 30, 2019

The -readonly notation is specifically only for mapped types, not for index signatures., despite their similar appearance. This is therefore working as intended and not a bug.

Do you know what โ€œsearch termsโ€ are? Itโ€™s hard to tell if you are intentionally ignoring the template or if there is a language issue.

dragomirtitiancommented, May 30, 2019

@bluelovers This whole post is not an issue but rather a question. Using -readonly is only valid in mapped types. There is no bug here, everything is the intended behavior.

Since you are already using Omit to remove length I am unsure what -readonly is trying to achieve. { length: number } wold be a writable property { readonly length: number } is a read-only property.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Mapped type for string doesn't work as expected. ...
When that is the case the compiler simple returns a type with the exact same property modifiers as the one on your input...
Read more >
Documentation - Mapped Types
Generating types by re-using an existing type.
Read more >
TypeScript errors and how to fix them
A list of common TypeScript errors and how to fix them.
Read more >
Fixing common type problems
Common type issues you may have and how to fix them. ... Include the warning or error message and, if possible, the code...
Read more >
readonly property typescript
In TypeScript, we can use the ' readonly ' keyword to make a property that can ... does not exist on type 'Readonly<...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found