Skip to content
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

TS 1.6: strict object literal assignment #208

Closed
jods4 opened this issue Sep 8, 2015 · 6 comments
Closed

TS 1.6: strict object literal assignment #208

jods4 opened this issue Sep 8, 2015 · 6 comments

Comments

@jods4
Copy link
Contributor

jods4 commented Sep 8, 2015

TS 1.6 introduces more strict type checking on object literals:
microsoft/TypeScript#3823

If an API is commonly meant to be extended, it's good that it adds a generic indexer to its definition for easier consumption.
I think it's the case for RouteConfig.

I had this in my code and it now fails in TS 1.6:

config.map([
  { route: 'test', name: 'test', moduleId: './Views/test', auth: 'admin' },
  // and many more routes like this
]);

The thing to notice is that I use auth to manage authentication and access rights for my routes (which I think is a recommended practice?).
Because auth is not declared in RouteConfig TS raised an error.

There are several ways to remove the error, but in this case I thought that it just made more sense to add [x: string]: any inside the RouteConfig declaration.

The consequence is that we still get intellisense for declared RouteConfig properties, but we may freely extend it with undeclared properties.

@bchavez
Copy link

bchavez commented Sep 8, 2015

👍 ran into this same issue when using TS 1.6. I also hang off auth and extra parameters in my routes.

@EisenbergEffect
Copy link
Contributor

@bryanrsmith How should we handle that? I don't think that we can do it with Babel, can we?

@bryanrsmith
Copy link
Contributor

@EisenbergEffect Babel does support it. I think we should instead encourage custom data to be added to a property specifically designed for arbitrary data. That would give us more flexibility in internal changes and future API additions. I thought we had such a property documented already, but I'm having trouble finding it now...

@jods4
Copy link
Contributor Author

jods4 commented Sep 9, 2015

Customizing the navigation pipeline in the doc illustrates using auth and friends directly on the route.
http://aurelia.io/docs.html#customizing-the-navigation-pipeline
Maybe the docs should be updated then.

I also note that when you have lots of routes, adding properties on sub-objects it's not very convenient (but doable).

@EisenbergEffect
Copy link
Contributor

@bryanrsmith Yes, there's actually already a property designated for that: settings which is recognized internally by the code. So, we just need to add that to our definitions as an optional property and make sure the settings object type has the type information described above.

@stephenlautier
Copy link

That's exactly how I fixed it on mine for the moment.
I added settings?: any; to the RouteConfig interface.

Might be better if it allows generic so we do get type strictness in our custom settings model.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants