ngParty / ng-metadata

Angular 2 decorators and utils for Angular 1.x
https://hotell.gitbooks.io/ng-metadata/content/
MIT License
355 stars 46 forks source link

Old provide syntax not working for directives #175

Closed vwochnik closed 7 years ago

vwochnik commented 7 years ago

The deprecated syntax for registering a directive using provide is not working, because there is a type mismatch.

This is how it was supposed to work:

import * as angular from 'angular';
import { Component, provide } from 'ng-metadata/core';

@Component({
  selector: 'hero',
  template: 'An angular 2 hero tag!'
})
export class HeroComponent {

  constructor(){

  }

}

angular.module('myApp')
  .directive( ...provide(HeroComponent) );

And this is the error:

test.ts(18,1): error TS2346: Supplied parameters do not match any signature of call target.

I tried getting more detailed information:

angular.module('myApp')
  .directive( "hero", provide(HeroComponent)[1] );

And here is the result:

test.ts(19,23): error TS2345: Argument of type 'Function | Type' is not assignable to parameter of type 'Injectable<IDirectiveFactory>'.
  Type 'Function' is not assignable to type 'Injectable<IDirectiveFactory>'.
    Type 'Function' is not assignable to type '(string | IDirectiveFactory)[]'.
      Property 'push' is missing in type 'Function'.

And here ends my expertise with TypeScript. I an choosing the old syntax for now because I want to get started without setting up an index.ts for our existing application.

aciccarello commented 7 years ago

I get a similar error message in my editor (VS Code) but it does not seem to affect my webpack build. I'm using TypeScript 2.0 but am still using Typings (not @types)

Hotell commented 7 years ago

there is a quick fix for that

add this to your global.d.ts

/// <reference path="../node_modules/ng-metadata/manual_typings/globals.d.ts" />