-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Speculation about #12596 Allow property (dotted) access syntax for types with string index signatures #16027
Comments
Other than this is how it used to work in TS, Why should these two be different? opt.noExisting;
opt["noExisting"]; |
This also has impacts for certain minifiers. I think there's a strong argument to allow opting in to the classic behavior (certainly I'd run with that flag on!). |
They are different in any case.
Sorry, don't get it. What does have impact? |
|
Your answer is it was working this way in TS 2.1, but my question was "Other than this is how it used to work in TS, Why should these two be different?" |
I'm sorry, but I understood you as that you think they should be the same. But even we forget about the fact how it was in TS 2.1 these two expressions are in fact different (in 2.3) for any type without index signature. So I can ask the same question: why? |
Is there an option to disable dotted syntax as it was before? I'm using Closure Compiler for angular 2 app and now I have to manually go through all the index-signature types to check if I access properties with quotes. Otherwise closure will rename those properties and I'll have errors at runtime. In angular it is ActivatedRoute.params, ActivatedRoute.queryParams, FormGroup.controls, FormGroup.value, ValidationErrors etc whose properties must be accessed with quoted syntax only. Also all the json data received from external resources which is typed as index-signature cannot be used with dot syntax. |
This was working before... Sort of annoying that its now not working... |
A type Similarly a type with an index signature, A type with no explicit member declaration or index signatures has no properties. e.g. The change only allows types with index signatures. I view this change as fix to an inconsistency in the system. |
One person's not working is another person's fix of a limitation. |
@mhegazy, @kitsonk Typescript is widely used by Angular 2 developers. |
That is a linting issue, not a typing/emit issue. If you project needs that rule, then it can be added. This has already been raised and discussed with the Angular 2 team... See #15206 (in particular this comment). Also, there is still an open proposal by the Angular 2 team at #14267 which is in this realm. |
kitsonk thanks, you're right, #14267 is the issue I need. |
This is implemented with |
Continue discussion on #12596 Allow property (dotted) access syntax for types with string index signatures (introduced in TS 2.2).
Let's consider a component with options.
All options the component uses are declared in its interface.
So to create an instance:
Now, imagine that component accepts a callback:
Let's imagine that inside onBeforeRender we need access to some value passed from parent content.
So we're adding an aspect to class and it depends on some data provided by a different aspect.
The easiest way to implement something like this was to add index signature into
Options
:It allowed us to extend components without subclassing.
Now (since TS 2.2) it has very serious impact - we lost type checking for
Options
type at all. The worst thing is that it could be not very clear for people migrating from previous versions. Everything still works. No breaking changes. But accidentally one can notice then compiler doesn't help anymore:So, probably we have two different cases here: a type as map and a type with optional extensibility.
I'd suggest to introduce optional index signature which implements the previous behavior:
this would mean the same as before:
The text was updated successfully, but these errors were encountered: