angular-ui / ui-router

The de-facto solution to flexible routing with nested views in AngularJS
http://ui-router.github.io/
MIT License
13.56k stars 3.01k forks source link

baseLocationService.d.ts:BaseLocationServices needs onChange overload #3750

Closed pgunsolley closed 5 years ago

pgunsolley commented 5 years ago

My version of UI-Router is: 1.0.20

tsconfig.json compiler options:

{
  "compilerOptions": {
    "strict": true,
    "module": "commonjs",
    "outDir": "www/staging/js",
    "rootDir": "src/",
    "sourceMap": false,
    "target": "es5",
    "experimentalDecorators": true
  }, //..
}

Typescript v3.1.3 reports:

node_modules/@uirouter/core/lib/vanilla/baseLocationService.d.ts(43,5): error TS2416: Property 
'onChange' in type 'BaseLocationServices' is not assignable to the same property in base type 
'LocationServices'.
  Type '(cb: EventListener) => () => Function[]' is not assignable to type '(callback: Function) => 
Function'.
    Types of parameters 'cb' and 'callback' are incompatible.
      Type 'Function' is not assignable to type 'EventListener'.
        Type 'Function' provides no match for the signature '(evt: Event): void'.

>> 1 non-emit-preventing type warning
>> Error: tsc return code: 2

There seems to be an incompatibility with the onChange method on LocationServices, which implements the UrlService.onChange signature of (callback: Function) => Function;

Was able to resolve this by adding the required overload, which satisfies the LocationServices interface:

onChange(cb: Function): Function;

I'm not sure if this is a sound fix, but it worked for me.

pgunsolley commented 5 years ago

Realized this should be in "core". Closing.