Misko Hevery b64a276d4b refactor(ivy): make return value of define(Component|Directive|Pipe|Injector|Injectable) private (#23371) (#23383)
Ivy definition looks something like this:

```
class MyService {
  static ngInjectableDef = defineInjectable({
    …
  });
}
```

Here the argument to `defineInjectable` is well known public contract which needs
to be honored in backward compatible way between versions. The type of the
return value of `defineInjectable` on the other hand is private and can change
shape drastically between versions without effecting backwards compatibility of
libraries publish to NPM. To our users it is effectively an opaque token.
For this reson why declare the return value of `defineInjectable` as `never`.

PR Close #23383
2018-04-14 20:40:14 -07:00

38 lines
922 B
TypeScript

/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {Injector, createInjector, defineInjectable, defineInjector} from '@angular/core';
export class RootService {
static ngInjectableDef = defineInjectable({
providedIn: 'root',
factory: () => new RootService(),
});
}
export class ScopedService {
static ngInjectableDef = defineInjectable({
providedIn: null,
factory: () => new ScopedService(),
});
doSomething(): void {
// tslint:disable-next-line:no-console
console.log('Ensure this isn\'t tree-shaken.');
}
}
export class DefinedInjector {
static ngInjectorDef = defineInjector({
factory: () => new DefinedInjector(),
providers: [ScopedService],
});
}
export const INJECTOR = createInjector(DefinedInjector);