Skip to content

Commit

Permalink
Fix types for older versions of Angular
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinpalkovic committed Mar 11, 2024
1 parent 8181266 commit fd040d1
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions code/frameworks/angular/src/client/public-types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable prettier/prettier */
/* eslint-disable @typescript-eslint/ban-ts-comment */
import {
AnnotatedStoryFn,
Args,
Expand Down Expand Up @@ -54,18 +56,13 @@ export type Preview = ProjectAnnotations<AngularRenderer>;
/**
* Utility type that transforms InputSignal and EventEmitter types
*/
type TransformComponentType<T> = TransformInputSignalType<TransformEventType<T>>;
type TransformComponentType<T> = TransformInputSignalType<TransformEventType<T>> extends unknown
? TransformEventType<T>
: TransformInputSignalType<TransformEventType<T>>;

type TransformInputSignalType<T> = {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore Angular < 17.2 doesn't have InputSignal
[K in keyof T]: T[K] extends AngularCore.InputSignal<infer E>
? E
: // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore Angular < 17.2 doesn't have InputSignalWithTransform
T[K] extends AngularCore.InputSignalWithTransform<any, infer U>
? U
: T[K];
/** @ts-ignore Angular < 17.2 doesn't have InputSignal */
[K in keyof T]: T[K] extends AngularCore.InputSignal<infer E> ? E : T[K] extends AngularCore.InputSignalWithTransform<any, infer U> ? U : T[K];
};

type TransformEventType<T> = {
Expand Down

0 comments on commit fd040d1

Please sign in to comment.