Issue a better error message when trying to use a modifier outside of a mapped type
See original GitHub issueTypeScript Version: 3.4.0-dev.201xxxxx
Search Terms:
Code
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:
- Created 4 years ago
- Comments:5 (5 by maintainers)
Top 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 >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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.
@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 removelength
I am unsure what-readonly
is trying to achieve.{ length: number }
wold be a writable property{ readonly length: number }
is a read-only property.