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

aurelia-cli beta 1.7/typescript 3.2.2 activationStrategy not allowed in router.config #628

Open
jeremy-holt opened this issue Dec 10, 2018 · 14 comments

Comments

@jeremy-holt
Copy link

I'm submitting a bug report

  • Library Version:
    aurelia-cli 1.0.7 beta

Please tell us about your environment:

  • Operating System:
    Windows 10

  • Node Version:
    10.11.0

  • Yarn Version:
    1.12.3

  • JSPM OR Webpack AND Version
    Webpack 4.27.1

  • Browser:
    Chrome 70.0.3538.110

  • Language:
    TypeScript 3.2.2

Current behavior:
Just ran yarn upgrade. It updated aurelia-cli from beta 5 to to beta 7

au build fails to compile on
route.config[map ..... activationStrategy:'replace".....

Expected/desired behavior:
It should compile

  • What is the expected behavior?

  • What is the motivation / use case for changing the behavior?

@3cp
Copy link
Member

3cp commented Dec 10, 2018

Can you show more details? It looks like a syntax error 'replace".

@jeremy-holt
Copy link
Author

Sorry - that was my bad typing. This was the actual code. I removed activationStrategy and it compiles now.

 public configureRouter(config: RouterConfiguration, router: Router) {
    config.title = "Amberwood";

    config.map([
      { route: ["", "home"], moduleId: PLATFORM.moduleName("modules/home/home"), name: "home", nav: true, title: "Home" },
      { route: "client/:id?", href: "#/client", moduleId: PLATFORM.moduleName("modules/client/client-edit"), name: "clientEdit", nav: true, title: "Clients" },
      {
        route: "contract/:id?", href: "#/contract", moduleId: PLATFORM.moduleName("modules/contract/contract-edit"), name: "contractEdit", nav: true, title: "Contracts",
        activationStrategy: "replace"
      },
      { route: "contract/print", moduleId: PLATFORM.moduleName("modules/printContract/print-contract"), name: "printContract", nav: false, title: "Print contract" },
      {

@3cp
Copy link
Member

3cp commented Dec 10, 2018

Sorry, I am not TS user. But can you try TS v3.1.6 + cli beta7? It could be the same reason for the bluebird import failure.

@jeremy-holt
Copy link
Author

jeremy-holt commented Dec 10, 2018

I suspect it was the upgrade to TS 3.2.2 - Stupidly I did them both at the same time. Each time I upgrade TS it finds more errors in my code (good thing!).
I do remember that putting in activationStrategy:"replace" never worked anyway. I ended up changing the query string when wanting to reload the same page. I should have removed activationStrategy from route.config at the time.

@3cp
Copy link
Member

3cp commented Dec 10, 2018

Based on the d.ts file, I guess you need to do

import {activationStrategy} from 'aurelia-router';
... activationStrategy: activationStrategy.replace,

@jeremy-holt
Copy link
Author

Nope - doesn't like that

image

@jeremy-holt
Copy link
Author

[ts]
Argument of type '({ route: string[]; moduleId: string; name: string; nav: boolean; title: string; } | { route: string; href: string; moduleId: string; name: string; nav: boolean; title: string; } | { route: string; href: string; ... 4 more ...; activationStrategy: string; } | { ...; } | { ...; } | { ...; })[]' is not assignable to parameter of type 'RouteConfig | RouteConfig[]'.
  Type '({ route: string[]; moduleId: string; name: string; nav: boolean; title: string; } | { route: string; href: string; moduleId: string; name: string; nav: boolean; title: string; } | { route: string; href: string; ... 4 more ...; activationStrategy: string; } | { ...; } | { ...; } | { ...; })[]' is not assignable to type 'RouteConfig[]'.
    Type '{ route: string[]; moduleId: string; name: string; nav: boolean; title: string; } | { route: string; href: string; moduleId: string; name: string; nav: boolean; title: string; } | { route: string; href: string; ... 4 more ...; activationStrategy: string; } | { ...; } | { ...; } | { ...; }' is not assignable to type 'RouteConfig'.
      Type '{ route: string; href: string; moduleId: string; name: string; nav: boolean; title: string; activationStrategy: string; }' is not assignable to type 'RouteConfig'.
        Types of property 'activationStrategy' are incompatible.
          Type 'string' is not assignable to type '"replace" | "no-change" | "invoke-lifecycle"'. [2345]

@jeremy-holt
Copy link
Author

OK - so it's just a problem in the d-ts. Need to change it to
activationStrategy: "replace" | "no-change" | "invoke-lifecycle"

@3cp
Copy link
Member

3cp commented Dec 10, 2018

@bigopon @davismj some typing problem with latest TS?

@jeremy-holt
Copy link
Author

Sorry - misspoke. It is correct in the d.ts. Can't see why it throws an error for 'replace'.

@davismj
Copy link
Member

davismj commented Mar 27, 2019

The router typings are correct. This is a bug or a quirk, depending on how positive you are, in TypeScript itself. See microsoft/TypeScript#10570.

config.map([
  { route: 'foo', moduleId: 'bar', activationStrategy: 'invoke-lifecycle' }
]);

What happens is that when you write the above TypeScript infers a type from the route config object literal and then tries to match it up with RouteConfig. In the first step, it recognizes 'invoke-lifecycle' as a string and not a string literal type, which is incompatible with the string literal type.

Workaround

config.map([
  { route: 'foo', moduleId: 'bar', activationStrategy: 'invoke-lifecycle' },
  { route: 'foo', moduleId: 'bar', activationStrategy: 'invoke-lifecycle' }
] as RouteConfig[]);

For now, this will work. You could also cast just the activationStrategy: <'invoke-lifecycle'>'invoke-lifecycle' or the individual route configs { ... } as RouteConfig,

Fix

We need to drop the string literal typing in favor of either a string or an enum-like.

@EisenbergEffect
Copy link
Contributor

I think this was fixed in the latest version of TS, wasn't it?

@davismj
Copy link
Member

davismj commented Mar 27, 2019

Haven't seen that. Issue is still open in MS repo and upgrading to latest is what brought my attention to this issue.

@ejuntu
Copy link

ejuntu commented Sep 16, 2019

I had this issue and got around with
var replaceStrat: any = "replace";
config.map([ { route: "", name: "index", moduleId: PLATFORM.moduleName("pages/index/index", "index"), title: "Front page", nav: 0, activationStrategy: replaceStrat },

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

No branches or pull requests

5 participants