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
This commit is contained in:
Misko Hevery
2018-04-14 09:18:38 -07:00
committed by Igor Minar
parent 815ae29b83
commit b64a276d4b
21 changed files with 105 additions and 96 deletions

View File

@ -162,7 +162,7 @@ export function defineComponent<T>(componentDefinition: {
* `PipeDefs`s. The function is necessary to be able to support forward declarations.
*/
pipes?: PipeTypesOrFactory | null;
}): ComponentDef<T> {
}): never {
const type = componentDefinition.type;
const pipeTypes = componentDefinition.pipes !;
const directiveTypes = componentDefinition.directives !;
@ -196,7 +196,7 @@ export function defineComponent<T>(componentDefinition: {
};
const feature = componentDefinition.features;
feature && feature.forEach((fn) => fn(def));
return def;
return def as never;
}
export function extractDirectiveDef(type: DirectiveType<any>& ComponentType<any>):
@ -400,7 +400,7 @@ export const defineDirective = defineComponent as any as<T>(directiveDefinition:
* See: {@link Directive.exportAs}
*/
exportAs?: string;
}) => DirectiveDef<T>;
}) => never;
/**
* Create a pipe definition object.
@ -428,11 +428,11 @@ export function definePipe<T>(pipeDef: {
/** Whether the pipe is pure. */
pure?: boolean
}): PipeDef<T> {
return <PipeDef<T>>{
}): never {
return (<PipeDef<T>>{
name: pipeDef.name,
n: pipeDef.factory,
pure: pipeDef.pure !== false,
onDestroy: pipeDef.type.prototype.ngOnDestroy || null
};
}) as never;
}