Skip to content

angular 1 StateProvider.state function should expect Ng1StateDeclaration parameter #3001

Closed
@AkosLukacs

Description

@AkosLukacs

I'm using TypeScript, after switching to ß2 $stateProvider.state() expects StateDeclaration parameter type, that doesn't have a template property for example. Therefore the following code doesn't compile (did work with ß1).

import * as uir from 'angular-ui-router';

//...

myModule.config(['$stateProvider', '$urlRouterProvider',
  ($stateProvider: uir.StateProvider, $urlRouterProvider: uir.UrlRouterProvider) => {

    $stateProvider
      .state('x', { url: '/x', template: '<p>x</p>' })     
  }]);

The compilation error:

Argument of type '{ url: string; template: string; }' is not assignable to parameter of type 'StateDeclaration'.
Object literal may only specify known properties, and 'template' does not exist in type 'StateDeclaration'.

There is an Ng1StateDeclaration interface, so came up with a temporary workaround for myself:

  export interface NG1StateProvider extends uir.StateProvider {
    state(name: string, definition: uir.Ng1StateDeclaration): NG1StateProvider;
    state(definition: uir.Ng1StateDeclaration): NG1StateProvider;
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions