@viewfly/core 0.6.1 → 0.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,10 +13,14 @@ export declare enum InjectFlags {
13
13
  /** 可选查找 */
14
14
  Optional = "Optional"
15
15
  }
16
+ /**
17
+ * 根据 token 推断返回数据类型
18
+ */
19
+ export type ExtractValueType<T> = T extends Type<any> ? InstanceType<T> : T extends AbstractType<infer K> ? K : T extends InjectionToken<infer V> ? V : never;
16
20
  /**
17
21
  * DI 容器抽象基类
18
22
  */
19
23
  export declare abstract class Injector {
20
24
  abstract parentInjector: Injector | null;
21
- abstract get<T>(token: Type<T> | AbstractType<T> | InjectionToken<T>, notFoundValue?: T, flags?: InjectFlags): T;
25
+ abstract get<T extends Type<any> | AbstractType<any> | InjectionToken<any>, U = never>(token: T, notFoundValue?: U, flags?: InjectFlags): ExtractValueType<T> | U;
22
26
  }
@@ -1,5 +1,5 @@
1
1
  import { Provider } from './provider';
2
- import { InjectFlags, Injector } from './injector';
2
+ import { ExtractValueType, InjectFlags, Injector } from './injector';
3
3
  import { NormalizedProvider } from './reflective-provider';
4
4
  import { AbstractType, Type } from './type';
5
5
  import { InjectionToken } from './injection-token';
@@ -12,7 +12,7 @@ export declare class ReflectiveInjector extends Injector {
12
12
  protected staticProviders: Provider[];
13
13
  protected scope?: Scope | undefined;
14
14
  protected normalizedProviders: NormalizedProvider[];
15
- protected recordValues: Map<InjectionToken<any> | Type<any> | AbstractType<any>, any>;
15
+ protected recordValues: Map<Type<any> | AbstractType<any> | InjectionToken<any>, any>;
16
16
  constructor(parentInjector: Injector | null, staticProviders: Provider[], scope?: Scope | undefined);
17
17
  /**
18
18
  * 用于获取当前注入器上下文内的实例、对象或数据
@@ -20,7 +20,7 @@ export declare class ReflectiveInjector extends Injector {
20
20
  * @param notFoundValue 如未查找到的返回值
21
21
  * @param flags 查询规则
22
22
  */
23
- get<T>(token: Type<T> | AbstractType<T> | InjectionToken<T>, notFoundValue?: T, flags?: InjectFlags): T;
23
+ get<T extends Type<any> | AbstractType<any> | InjectionToken<any>, U = never>(token: T, notFoundValue?: U, flags?: InjectFlags): ExtractValueType<T> | U;
24
24
  private getValue;
25
25
  /**
26
26
  * 解决并获取依赖参数
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@viewfly/core",
3
- "version": "0.6.1",
3
+ "version": "0.6.3",
4
4
  "description": "Viewfly is a simple and easy-to-use JavaScript framework with an intuitive development experience.",
5
5
  "main": "./bundles/index.js",
6
6
  "module": "./bundles/index.esm.js",
@@ -47,7 +47,7 @@
47
47
  "bugs": {
48
48
  "url": "https://github.com/viewfly/viewfly.git/issues"
49
49
  },
50
- "gitHead": "95ed600209322e44d2bd7d2eb62a1868629d9d68",
50
+ "gitHead": "67d1ad7eff77c30dfafa3bc6a51a21ecde114aec",
51
51
  "dependencies": {
52
52
  "reflect-metadata": "^0.1.13"
53
53
  }