GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — Improved support for read-only arrays and tuples by ahejlsberg · Pull Request #29435 · microsoft/TypeScript Conversation
|
| "category": "Error", | ||
| "code": 1353 | ||
| }, | ||
| "'readonly' type modifier is only permitted on array and typle types.": { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Typo: typle to tuple.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Jordi Oliveras Rovira (@j-oliveras) Oops. Thanks!
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| } | ||
| else if (node.operator === SyntaxKind.ReadonlyKeyword) { | ||
| if (node.type.kind !== SyntaxKind.ArrayType && node.type.kind !== SyntaxKind.TupleType) { | ||
| return grammarErrorOnFirstToken(node, Diagnostics.readonly_type_modifier_is_only_permitted_on_array_and_typle_types, tokenToString(SyntaxKind.SymbolKeyword)); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Add test for this?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| switch (operator) { | ||
| case SyntaxKind.KeyOfKeyword: | ||
| case SyntaxKind.UniqueKeyword: | ||
| case SyntaxKind.ReadonlyKeyword: |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Think we need test/handling for .d.ts generation and decorator for this new typeNode kind.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Does this improved support for readonly arrays mean it's now possible to have readonly array/tuples as the type of a rest argument?
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@Kovensky Isn't in the PR currently, but I see no reason why we couldn't support it. I will fix it, it's just a minor change. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
+1 for .d.ts emit coverage - the only .d.ts currently in this set has semantic errors in its originating file, which makes it shaky at best
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I think having decorator test is good idea too.. since we normally forget that when we enable new kind of type annotation. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
// @emitDecoratorMetadata: true // @experimentalDecorators: true // @declaration: true declare const someDec: any; class A { @someDec j: readonly string[]; @someDec k: readonly [string, number]; } |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Is this an intended change that a single 'readonly' is no longer parsed as a type? (This is not a sample from real code, just a test case.) Seems that it is not a serious issue, but would be nice to know if this was planned, as you still may declare a type named 'readonly' but cannot use it anymore. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Anton Lobov (@zhuravlikjb) No, that was not intended. I will look at getting it fixed. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Using a version of TypeScript that contains this PR creates declaration files which are not compatible with older versions of TypeScript. In case someone else has the same problem: I created a transformer to downlevel readonly array types in declaration files: https://github.com/ajafff/ts-transform-readonly-array |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Anders Hejlsberg (@ahejlsberg) This feature leaved some large bugs (Maybe regression). Please fix them: #29442 #29702 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
falsandtru (@falsandtru) Those issues are not related to this PR, but I have a fix in #29740. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Indeed, I thought another PR. Anyway, thanks for fixing. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I assume the extension to |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Is it still possible to declare a writable property with an immutable array? For example, constructable stylesheets defines element.shadowRoot.adoptedStyleSheets = [...element.shadowRoot.adoptedStyleSheets, styleSheet] |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.