angular-cn/modules/@angular/compiler/src
Miško Hevery d169c2434e feat(core): Add type information to injector.get() (#13785)
- Introduce `InjectionToken<T>` which is a parameterized and type-safe
  version of `OpaqueToken`.

DEPRECATION:
- `OpaqueToken` is now deprecated, use `InjectionToken<T>` instead.
- `Injector.get(token: any, notFoundValue?: any): any` is now deprecated
  use the same method which is now overloaded as
  `Injector.get<T>(token: Type<T>|InjectionToken<T>, notFoundValue?: T): T;`.

Migration
- Replace `OpaqueToken` with `InjectionToken<?>` and parameterize it.
- Migrate your code to only use `Type<?>` or `InjectionToken<?>` as
  injection tokens. Using other tokens will not be supported in the
  future.

BREAKING CHANGE:
- Because `injector.get()` is now parameterize it is possible that code
  which used to work no longer type checks. Example would be if one
  injects `Foo` but configures it as `{provide: Foo, useClass: MockFoo}`.
  The injection instance will be that of `MockFoo` but the type will be
  `Foo` instead of `any` as in the past. This means that it was possible
  to call a method on `MockFoo` in the past which now will fail type
  check. See this example:

```
class Foo {}
class MockFoo extends Foo {
  setupMock();
}

var PROVIDERS = [
  {provide: Foo, useClass: MockFoo}
];

...

function myTest(injector: Injector) {
  var foo = injector.get(Foo);
  // This line used to work since `foo` used to be `any` before this
  // change, it will now be `Foo`, and `Foo` does not have `setUpMock()`.
  // The fix is to downcast: `injector.get(Foo) as MockFoo`.
  foo.setUpMock();
}
```

PR Close #13785
2017-01-17 15:34:54 -06:00
..
animation feat(animations): support function types in transitions 2017-01-06 19:29:46 -05:00
aot feat(core): Add type information to injector.get() (#13785) 2017-01-17 15:34:54 -06:00
compiler_util refactor(Compiler): misc cleanup 2017-01-09 19:32:01 -05:00
css_parser refactor(): use const and let instead of var 2016-11-12 16:40:17 -08:00
expression_parser refactor(Compiler): misc cleanup 2017-01-09 19:32:01 -05:00
i18n fix(i18n): translate attributes inside elements marked for translation 2017-01-09 19:33:03 -05:00
jit feat(core): Add type information to injector.get() (#13785) 2017-01-17 15:34:54 -06:00
ml_parser refactor(Compiler): misc cleanup 2017-01-09 19:32:01 -05:00
output refactor(Compiler): misc cleanup 2017-01-09 19:32:01 -05:00
schema refactor(compiler): store metadata of top level symbols also in summaries (#13289) 2016-12-15 09:12:40 -08:00
template_parser feat(core): Add type information to injector.get() (#13785) 2017-01-17 15:34:54 -06:00
view_compiler fix(animations): fix internal jscompiler issue and AOT quoting (#13798) 2017-01-13 13:52:00 -06:00
assertions.ts refactor(): use const and let instead of var 2016-11-12 16:40:17 -08:00
chars.ts chore(lint): Added license headers to most TypeScript files 2016-06-23 09:47:54 -07:00
compile_metadata.ts feat(animations): support function types in transitions 2017-01-06 19:29:46 -05:00
config.ts refactor(compiler): remove unneeded fields from metadata 2016-11-28 15:19:23 -08:00
directive_normalizer.ts refactor(Compiler): misc cleanup 2017-01-09 19:32:01 -05:00
directive_resolver.ts refactor(Compiler): misc cleanup 2017-01-09 19:32:01 -05:00
directive_wrapper_compiler.ts refactor(Compiler): misc cleanup 2017-01-09 19:32:01 -05:00
facade repackaging: all the repackaging changes squashed 2016-05-01 20:51:00 -07:00
identifiers.ts refactor(Compiler): misc cleanup 2017-01-09 19:32:01 -05:00
injectable.ts refactor(compiler): store metadata of top level symbols also in summaries (#13289) 2016-12-15 09:12:40 -08:00
lifecycle_reflector.ts refactor(core): delete unused reflector code 2016-10-17 23:17:34 -07:00
metadata_resolver.ts feat(core): Add type information to injector.get() (#13785) 2017-01-17 15:34:54 -06:00
ng_module_compiler.ts refactor(Compiler): misc cleanup 2017-01-09 19:32:01 -05:00
ng_module_resolver.ts refactor(Compiler): misc cleanup 2017-01-09 19:32:01 -05:00
parse_util.ts fix(compiler): narrow the span reported for invalid pipes 2016-12-13 11:23:47 -08:00
pipe_resolver.ts refactor(Compiler): misc cleanup 2017-01-09 19:32:01 -05:00
private_import_core.ts refactor(compiler): generate less code for bindings to DOM elements 2017-01-03 13:05:05 -08:00
provider_analyzer.ts refactor(Compiler): misc cleanup 2017-01-09 19:32:01 -05:00
resource_loader.ts fix(platform-browser-dynamic): Rename CACHED_TEMPLATE_PROVIDER to RESOURCE_CACHE_PROVIDER (#10866) 2016-08-17 09:24:44 -07:00
selector.ts fix(Compiler): allow "." in attribute selectors (#13653) 2016-12-27 15:23:49 -08:00
shadow_css.ts refactor(): use const and let instead of var 2016-11-12 16:40:17 -08:00
style_compiler.ts refactor(compiler): store metadata of top level symbols also in summaries (#13289) 2016-12-15 09:12:40 -08:00
style_url_resolver.ts fix(compiler): ignore @import in comments (#13368) 2016-12-20 17:51:02 -08:00
summary_resolver.ts feat(compiler): generate proper reexports in `.ngfactory.ts` files to not need transitive deps for compiling `.ngfactory.ts` files. (#13524) 2016-12-27 09:36:47 -08:00
url_resolver.ts feat(core): Add type information to injector.get() (#13785) 2017-01-17 15:34:54 -06:00
util.ts refactor(compiler): don't print stack trace on template parse errors (#13390) 2016-12-15 13:07:12 -08:00
version.ts fix: display framework version on bootstrapped component (#13252) 2016-12-06 16:21:07 -08:00