Skip to content

Commit

Permalink
fix(build): create angular typings override so we don't have to impor…
Browse files Browse the repository at this point in the history
…t them to source

- bump to typescript@next which resolves issues with type declaration generation
- extract angular module type overrides to separate file which should by included within consumer app
- make global.d.ts truly global
- use only ng.* namespace for types ( no angular )
- update tsconfig to make tsc faster, stronger ;)
- fix compile errors introduced by latest ts 2.1 with better any type inference
- fix NgModule decorator options types to properly allow registering downgraded ng2 entities

Closes #175, #177

BREAKING CHANGE:

We now officialy support only angular typings provided via npm `@types/*` and also typescript 2.x

- your existing typings provided by `typings` might not work
- from now on if you wanna use deprecated `provide` function from `ng-metadata/core` with registration within `angular.module().directive|service|filter` you have to explicitly include angular types extension provided by ng-metadata from `node_modules/ng-metadata/manual_typings/angular-extension.d.ts`

Before:
```typescript
// global.d.ts
/// <reference path="../node_modules/ng-metadata/manual_typings/globals.d.ts" />
```

After:
```typescript
/// <reference path="../node_modules/ng-metadata/manual_typings/angular-extension.d.ts" />
```

or you can include it from within your tsconfig.json like this:
```json
{
  "include":[
    "src/**/*.ts"
  ],
  "files": [
    "node_modules/ng-metadata/manual_typings/angular-extension.d.ts"
  ],
  "exclude": [
    "node_modules"
  ]
}
```
  • Loading branch information
Hotell committed Nov 20, 2016
1 parent 82f72ca commit 3153bca
Show file tree
Hide file tree
Showing 19 changed files with 2,171 additions and 133 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ npm-debug.log
*.js
*.map
*.d.ts
!manual_typings/globals.d.ts
!manual_typings/**/*.d.ts
!playground/ng-metadata.legacy.d.ts
typings
test/__uglifyTest.js
Expand Down
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ npm-debug.log
*.ts
# allow only ambient type definitions
!*.d.ts
manual_typings/globals.d.ts
manual_typings/overrides
.travis.yml
.editorconfig
.npmignore
Expand Down
102 changes: 102 additions & 0 deletions manual_typings/angular-extension.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/// <reference types="angular" />

import * as angular from 'angular';

type ProvideSpreadType = string|Function;

///////////////////////////////////////////////////////////////////////////////
// ngMetadata angular module overrides
// - add angular1 module overrides for proper ...provide handling
///////////////////////////////////////////////////////////////////////////////
declare module 'angular' {
interface IParseService{
( exp: string, interceptorFn?: Function, expensiveChecks?: boolean ): ICompiledExpression
}
interface IModule {
value(...args: ProvideSpreadType[]): IModule;
constant(...args: ProvideSpreadType[]): IModule;
directive(...args: ProvideSpreadType[]): IModule;
filter(...args: ProvideSpreadType[]): IModule;
service(...args: ProvideSpreadType[]): IModule;
provider(...args: ProvideSpreadType[]): IModule;
}
///////////////////////////////////////////////////////////////////////////
// AUTO module (angular.js)
///////////////////////////////////////////////////////////////////////////
export module auto {

///////////////////////////////////////////////////////////////////////
// ProvideService
// see http://docs.angularjs.org/api/AUTO.$provide
///////////////////////////////////////////////////////////////////////
interface IProvideService {
// Documentation says it returns the registered instance, but actual
// implementation does not return anything.
// constant(name: string, value: any): any;
/**
* Register a constant service, such as a string, a number, an array, an object or a function, with the $injector. Unlike value it can be injected into a module configuration function (see config) and it cannot be overridden by an Angular decorator.
*/
constant(...args: ProvideSpreadType[]): void;

/**
* Register a service decorator with the $injector. A service decorator intercepts the creation of a service, allowing it to override or modify the behaviour of the service. The object returned by the decorator may be the original service, or a new service object which replaces or wraps and delegates to the original service.
*
* @param name The name of the service to decorate.
* @param decorator This function will be invoked when the service needs to be instantiated and should return the decorated service instance. The function is called using the injector.invoke method and is therefore fully injectable. Local injection arguments:
*
* $delegate - The original service instance, which can be monkey patched, configured, decorated or delegated to.
*/
//decorator(name: string, decorator: Function): void;
/**
* Register a service decorator with the $injector. A service decorator intercepts the creation of a service, allowing it to override or modify the behaviour of the service. The object returned by the decorator may be the original service, or a new service object which replaces or wraps and delegates to the original service.
*
* @param name The name of the service to decorate.
* @param inlineAnnotatedFunction This function will be invoked when the service needs to be instantiated and should return the decorated service instance. The function is called using the injector.invoke method and is therefore fully injectable. Local injection arguments:
*
* $delegate - The original service instance, which can be monkey patched, configured, decorated or delegated to.
*/
//decorator(name: string, inlineAnnotatedFunction: any[]): void;
factory(...args: ProvideSpreadType[]): IServiceProvider;
provider(...args: ProvideSpreadType[]): IServiceProvider;
service(...args: ProvideSpreadType[]): IServiceProvider;
value(...args: ProvideSpreadType[]): IServiceProvider;
}

}

// /**
// * $rootScope - $rootScopeProvider - service in module ng
// * see https://docs.angularjs.org/api/ng/type/$rootScope.Scope and https://docs.angularjs.org/api/ng/service/$rootScope
// */
// interface IRootScopeService {
//
// // private members
// $$postDigest( callback: Function ): void,
// $$postDigestQueue: Function[],
// $$applyAsyncQueue: Function[],
// $$asyncQueue: Function[],
// $$watchers: Watchers[],
// $$watchersCount: number,
// $$listenerCount: Object,
// $$listeners: Object,
// $$destroyed: boolean,
// $$childHead: ng.IScope,
// $$childTail: ng.IScope,
// $$prevSibling: ng.IScope,
// $$nextSibling: ng.IScope,
//
// // ngMetadata private members
// $$disconnected?: boolean,
//
// }
//
// /* @private */
// interface Watchers {
// eq: boolean,
// exp: ( s: any, l: any, a: any, i: any ) => any,
// fn: ( newValue: any, oldValue: any ) => any,
// get: ( s: any, l: any, a: any, i: any ) => any,
// last: any
// }

}
107 changes: 1 addition & 106 deletions manual_typings/globals.d.ts
Original file line number Diff line number Diff line change
@@ -1,106 +1 @@
import * as angular from 'angular';

///////////////////////////////////////////////////////////////////////////////
// functions attached to global object (window)
///////////////////////////////////////////////////////////////////////////////
declare global {
type StringMap = {[key: string]: string};
type ProvideSpreadType = string|Function;
}

///////////////////////////////////////////////////////////////////////////////
// custom angular module overrides
// - add angular1 module overrides for proper ...provide handling
///////////////////////////////////////////////////////////////////////////////
declare module 'angular' {
interface IParseService{
( exp: string, interceptorFn?: Function, expensiveChecks?: boolean ): ng.ICompiledExpression
}
interface IModule {
value(...args: ProvideSpreadType[]): IModule;
constant(...args: ProvideSpreadType[]): IModule;
directive(...args: ProvideSpreadType[]): IModule;
filter(...args: ProvideSpreadType[]): IModule;
service(...args: ProvideSpreadType[]): IModule;
provider(...args: ProvideSpreadType[]): IModule;
}
///////////////////////////////////////////////////////////////////////////
// AUTO module (angular.js)
///////////////////////////////////////////////////////////////////////////
export module auto {

///////////////////////////////////////////////////////////////////////
// ProvideService
// see http://docs.angularjs.org/api/AUTO.$provide
///////////////////////////////////////////////////////////////////////
interface IProvideService {
// Documentation says it returns the registered instance, but actual
// implementation does not return anything.
// constant(name: string, value: any): any;
/**
* Register a constant service, such as a string, a number, an array, an object or a function, with the $injector. Unlike value it can be injected into a module configuration function (see config) and it cannot be overridden by an Angular decorator.
*/
constant(...args: ProvideSpreadType[]): void;

/**
* Register a service decorator with the $injector. A service decorator intercepts the creation of a service, allowing it to override or modify the behaviour of the service. The object returned by the decorator may be the original service, or a new service object which replaces or wraps and delegates to the original service.
*
* @param name The name of the service to decorate.
* @param decorator This function will be invoked when the service needs to be instantiated and should return the decorated service instance. The function is called using the injector.invoke method and is therefore fully injectable. Local injection arguments:
*
* $delegate - The original service instance, which can be monkey patched, configured, decorated or delegated to.
*/
//decorator(name: string, decorator: Function): void;
/**
* Register a service decorator with the $injector. A service decorator intercepts the creation of a service, allowing it to override or modify the behaviour of the service. The object returned by the decorator may be the original service, or a new service object which replaces or wraps and delegates to the original service.
*
* @param name The name of the service to decorate.
* @param inlineAnnotatedFunction This function will be invoked when the service needs to be instantiated and should return the decorated service instance. The function is called using the injector.invoke method and is therefore fully injectable. Local injection arguments:
*
* $delegate - The original service instance, which can be monkey patched, configured, decorated or delegated to.
*/
//decorator(name: string, inlineAnnotatedFunction: any[]): void;
factory(...args: ProvideSpreadType[]): IServiceProvider;
provider(...args: ProvideSpreadType[]): IServiceProvider;
service(...args: ProvideSpreadType[]): IServiceProvider;
value(...args: ProvideSpreadType[]): IServiceProvider;
}

}

/**
* $rootScope - $rootScopeProvider - service in module ng
* see https://docs.angularjs.org/api/ng/type/$rootScope.Scope and https://docs.angularjs.org/api/ng/service/$rootScope
*/
interface IRootScopeService {

// private members
$$postDigest( callback: Function ): void,
$$postDigestQueue: Function[],
$$applyAsyncQueue: Function[],
$$asyncQueue: Function[],
$$watchers: Watchers[],
$$watchersCount: number,
$$listenerCount: Object,
$$listeners: Object,
$$destroyed: boolean,
$$childHead: IScope,
$$childTail: IScope,
$$prevSibling: IScope,
$$nextSibling: IScope,

// ngMetadata private members
$$disconnected?: boolean,

}

/* @private */
interface Watchers {
eq: boolean,
exp: ( s: any, l: any, a: any, i: any ) => any,
fn: ( newValue: any, oldValue: any ) => any,
get: ( s: any, l: any, a: any, i: any ) => any,
last: any
}

}
type StringMap = {[key: string]: string};
Loading

0 comments on commit 3153bca

Please sign in to comment.