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

HookMatchCriteria compile error in TypeScript with strict null checks #33

Closed
schoel-bis opened this issue Jan 26, 2017 · 7 comments
Closed
Labels
Milestone

Comments

@schoel-bis
Copy link

Compiling a typescript application with strict null checks enabled will produce a number of errors due to the definition of HookMatchCriteria:

ERROR in /home/schoel/Projekte/javascript/i3ge/node_modules/ui-router-core/lib/transition/interface.d.ts
(735,5): error TS2411: Property 'to' of type 'string | boolean | Predicate | undefined' is not assignable to string index type 'string | boolean | Predicate'.

ERROR in /home/schoel/Projekte/javascript/i3ge/node_modules/ui-router-core/lib/transition/interface.d.ts
(737,5): error TS2411: Property 'from' of type 'string | boolean | Predicate | undefined' is not assignable to string index type 'string | boolean | Predicate'.

ERROR in /home/schoel/Projekte/javascript/i3ge/node_modules/ui-router-core/lib/transition/interface.d.ts
(739,5): error TS2411: Property 'exiting' of type 'string | boolean | Predicate | undefined' is not assignable to string index type 'string | boolean | Predicate'.

ERROR in /home/schoel/Projekte/javascript/i3ge/node_modules/ui-router-core/lib/transition/interface.d.ts
(741,5): error TS2411: Property 'retained' of type 'string | boolean | Predicate | undefined' is not assignable to string index type 'string | boolean | Predicate'.

ERROR in /home/schoel/Projekte/javascript/i3ge/node_modules/ui-router-core/lib/transition/interface.d.ts
(743,5): error TS2411: Property 'entering' of type 'string | boolean | Predicate | undefined' is not assignable to string index type 'string | boolean | Predicate'.

This is because the type of the string keyed property ([key: string]: HookMatchCriterion) has to match the type any other property in the interface. All other properties are optional, though, and thus of type HookMatchCriterion | undefined. Changing the type of the string keyed property to HookMatchCriterion | undefined resolves the issue.

@helmutschneider
Copy link

@christopherthielen Not sure why this was closed - the issue still exists in the current code:

export interface HookMatchCriteria {
  [key: string]: HookMatchCriterion;
  to?: HookMatchCriterion | undefined;
  from?: HookMatchCriterion | undefined;
  exiting?: HookMatchCriterion | undefined;
  retained?: HookMatchCriterion | undefined;
  entering?: HookMatchCriterion | undefined;
}

[key: string]: HookMatchCriterion is typed as non-undefined which causes the compilation to fail on all the optional properties. The code should probably read:

export interface HookMatchCriteria {
    [key: string]: HookMatchCriterion | undefined;
    to?: HookMatchCriterion;
    from?: HookMatchCriterion;
    exiting?: HookMatchCriterion;
    retained?: HookMatchCriterion;
    entering?: HookMatchCriterion;
}

@mrahhal
Copy link
Contributor

mrahhal commented Jun 6, 2017

Also still facing this.

@AnimaLupi
Copy link

AnimaLupi commented Jun 15, 2017

Same issue here.

EDIT: Investigating atm as I'm probably on an older version due to compatibility with the rest of the app.

EDIT2: It seems to be an issue even with latest ui-router/core 5.0.4.

@mrahhal
Copy link
Contributor

mrahhal commented Jun 15, 2017

Right now this is the only blocker for me to use the "strict" option. A bit frustrating.

@gaui
Copy link

gaui commented Jul 19, 2017

When is 0ae585e going to be released? I added that patch and everything compiles.

@gaui
Copy link

gaui commented Aug 10, 2017

Chris 🙏

@christopherthielen
Copy link
Member

New core and angularjs releases tonight

wawyed pushed a commit to wawyed/core that referenced this issue Mar 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants