Skip to content

Commit

Permalink
feat: 馃幐 fix input/output type inference (#651)
Browse files Browse the repository at this point in the history
* feat: 馃幐 fix input/output type inference

* chore!: drop support for angular <17.3.0

BREAKING CHANGE: using Angular types not available in versions lower
than 17.3.0
  • Loading branch information
kfrancois committed Mar 21, 2024
1 parent e522c99 commit 8cacdda
Show file tree
Hide file tree
Showing 5 changed files with 1,109 additions and 951 deletions.
44 changes: 22 additions & 22 deletions package.json
Expand Up @@ -31,38 +31,38 @@
},
"devDependencies": {
"@angular-builders/jest": "^17.0.0",
"@angular-devkit/build-angular": "^17.1.1",
"@angular-devkit/schematics": "^17.1.1",
"@angular-eslint/builder": "17.2.1",
"@angular-eslint/eslint-plugin": "17.2.1",
"@angular-eslint/eslint-plugin-template": "17.2.1",
"@angular-eslint/schematics": "17.2.1",
"@angular-eslint/template-parser": "17.2.1",
"@angular/animations": "^17.1.1",
"@angular/cdk": "^17.1.1",
"@angular/cli": "^17.1.1",
"@angular/common": "^17.1.1",
"@angular/compiler": "^17.1.1",
"@angular/compiler-cli": "^17.1.1",
"@angular/core": "^17.1.0",
"@angular/forms": "^17.1.1",
"@angular/language-service": "^17.1.1",
"@angular/platform-browser": "^17.1.1",
"@angular/platform-browser-dynamic": "^17.1.1",
"@angular/router": "17.1.1",
"@angular-devkit/build-angular": "^17.3.0",
"@angular-devkit/schematics": "^17.3.0",
"@angular-eslint/builder": "17.3.0",
"@angular-eslint/eslint-plugin": "17.3.0",
"@angular-eslint/eslint-plugin-template": "17.3.0",
"@angular-eslint/schematics": "17.3.0",
"@angular-eslint/template-parser": "17.3.0",
"@angular/animations": "^17.3.0",
"@angular/cdk": "^17.3.0",
"@angular/cli": "^17.3.0",
"@angular/common": "^17.3.0",
"@angular/compiler": "^17.3.0",
"@angular/compiler-cli": "^17.3.0",
"@angular/core": "^17.3.0",
"@angular/forms": "^17.3.0",
"@angular/language-service": "^17.3.0",
"@angular/platform-browser": "^17.3.0",
"@angular/platform-browser-dynamic": "^17.3.0",
"@angular/router": "17.3.0",
"@commitlint/cli": "17.3.0",
"@commitlint/config-angular": "17.3.0",
"@commitlint/config-conventional": "17.3.0",
"@types/jasmine": "5.1.4",
"@types/jest": "29.5.11",
"@types/node": "20.10.4",
"@typescript-eslint/eslint-plugin": "^6.13.2",
"@typescript-eslint/parser": "^6.13.2",
"@typescript-eslint/eslint-plugin": "^7.2.0",
"@typescript-eslint/parser": "^7.2.0",
"all-contributors-cli": "^6.19.0",
"core-js": "^3.9.1",
"cross-env": "^5.1.4",
"cz-conventional-changelog": "^3.3.0",
"eslint": "^8.55.0",
"eslint": "^8.57.0",
"git-cz": "^4.7.6",
"helpful-decorators": "^2.1.0",
"husky": "^8.0.2",
Expand Down
6 changes: 3 additions & 3 deletions projects/spectator/package.json
Expand Up @@ -29,9 +29,9 @@
"tslib": "^2.6.2"
},
"peerDependencies": {
"@angular/common": ">= 17.0.0",
"@angular/router": ">= 17.0.0",
"@angular/animations": ">= 17.0.0"
"@angular/common": ">= 17.3.0",
"@angular/router": ">= 17.3.0",
"@angular/animations": ">= 17.3.0"
},
"schematics": "./schematics/collection.json"
}
4 changes: 2 additions & 2 deletions projects/spectator/src/lib/base/dom-spectator.ts
Expand Up @@ -12,7 +12,7 @@ import { SpyObject } from '../mock';
import { selectOption } from '../select-option';
import { Token } from '../token';
import { typeInElement } from '../type-in-element';
import { EventEmitterType, KeyboardEventOptions, KeysMatching, QueryOptions, QueryType, SpectatorElement, isString } from '../types';
import { OutputType, KeyboardEventOptions, KeysMatching, QueryOptions, QueryType, SpectatorElement, isString } from '../types';

import { BaseSpectator } from './base-spectator';

Expand Down Expand Up @@ -260,7 +260,7 @@ export abstract class DomSpectator<I> extends BaseSpectator {
public triggerEventHandler<C = any, K extends KeysMatching<C, EventEmitter<any>> = any>(
directiveOrSelector: Type<C> | string | DebugElement,
eventName: K,
eventObj: EventEmitterType<C[K]>,
eventObj: OutputType<C[K]>,
options?: { root: boolean },
) {
const triggerDebugElement = this.getDebugElement(directiveOrSelector, options);
Expand Down
6 changes: 3 additions & 3 deletions projects/spectator/src/lib/types.ts
@@ -1,4 +1,4 @@
import { DebugElement, ElementRef, EventEmitter, InputSignal, OnDestroy, Type } from '@angular/core';
import { DebugElement, ElementRef, EventEmitter, InputSignalWithTransform, OnDestroy, OutputRef, Type } from '@angular/core';

import { DOMSelector } from './dom-selectors';
import { Token } from './token';
Expand All @@ -8,7 +8,7 @@ type OptionalPropertyNames<T> = {
}[keyof T];
type OptionalProperties<T> = Pick<T, OptionalPropertyNames<T>>;

export type InferInputSignal<T> = T extends InputSignal<infer K> ? K : T;
export type InferInputSignal<T> = T extends InputSignalWithTransform<infer K, infer _> ? K : T;
export type InferInputSignals<C> = {
[P in keyof C]+?: InferInputSignal<C[P]>;
};
Expand All @@ -24,7 +24,7 @@ export interface QueryOptions<R> {
parentSelector?: Type<any> | string;
}

export type EventEmitterType<P> = P extends EventEmitter<infer T> ? T : never;
export type OutputType<P> = P extends EventEmitter<infer T> ? T : P extends OutputRef<infer T> ? T : never;

export type KeysMatching<T, V> = { [K in keyof T]: T[K] extends V ? K : never }[keyof T];

Expand Down

0 comments on commit 8cacdda

Please sign in to comment.