Skip to content

Commit

Permalink
fix(plugin): add string to input generic
Browse files Browse the repository at this point in the history
  • Loading branch information
timdeschryver committed May 18, 2024
1 parent 5baf2fc commit 648bfec
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,12 @@ export class MyCmp {
withDefaultAlias = input(123, { alias: 'defaultAlias' });
withoutDefaultAlias = input<number | undefined>(undefined, { alias: 'noDefaultAlias' });
justAStringAlias = input('', { alias: 'stringAlias' });
withTransform = input<boolean, string | ''>(booleanAttribute(false), { transform: booleanAttribute });
withTransform = input<boolean, boolean | string>(booleanAttribute(false), { transform: booleanAttribute });
requiredInput = input.required<string>();
requiredWithAlias = input.required<boolean>({ alias: 'requiredAlias' });
requiredWithAliasAndTransform = input.required<number, string | ''>({ alias: 'transformedRequiredAlias', transform: numberAttribute });
requiredWithAliasAndTransform = input.required<number, number | string>({ alias: 'transformedRequiredAlias', transform: numberAttribute });
withTransformWithoutType = input(booleanAttribute(false), { transform: booleanAttribute });
requiredWithTransformWithoutType = input(numberAttribute(1), { transform: numberAttribute });
@Input() set leaveMeAlone(value: number) {
console.log('setter', value);
Expand Down Expand Up @@ -312,13 +314,15 @@ export class MyCmp {
withDefaultAlias = input(123, { alias: 'defaultAlias' });
withoutDefaultAlias = input<number | undefined>(undefined, { alias: 'noDefaultAlias' });
justAStringAlias = input('', { alias: 'stringAlias' });
withTransform = input<boolean, string | ''>(booleanAttribute(false), { transform: booleanAttribute });
withTransform = input<boolean, boolean | string>(booleanAttribute(false), { transform: booleanAttribute });
requiredInput = input.required<string>();
requiredWithAlias = input.required<boolean>({ alias: 'requiredAlias' });
/*
* @description I go with requiredWithAliasAndTransform
*/
requiredWithAliasAndTransform = input.required<number, string | ''>({ alias: 'transformedRequiredAlias', transform: numberAttribute });
requiredWithAliasAndTransform = input.required<number, number | string>({ alias: 'transformedRequiredAlias', transform: numberAttribute });
withTransformWithoutType = input(booleanAttribute(false), { transform: booleanAttribute });
requiredWithTransformWithoutType = input(numberAttribute(1), { transform: numberAttribute });
@Input() set leaveMeAlone(value: number) {
console.log('setter', value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,12 @@ export class MyCmp {
@Input({ alias: 'defaultAlias' }) withDefaultAlias = 123;
@Input({ alias: 'noDefaultAlias'}) withoutDefaultAlias?: number;
@Input('stringAlias') justAStringAlias = '';
@Input({ transform: booleanAttribute }) withTransform: string | '' = false;
@Input({ transform: booleanAttribute }) withTransform: boolean = false;
@Input({ required: true }) requiredInput!: string;
@Input({ required: true, alias: 'requiredAlias' }) requiredWithAlias!: boolean;
@Input({ required: true, alias: 'transformedRequiredAlias', transform: numberAttribute }) requiredWithAliasAndTransform!: string | '';
@Input({ required: true, alias: 'transformedRequiredAlias', transform: numberAttribute }) requiredWithAliasAndTransform!: number;
@Input({ transform: booleanAttribute }) withTransformWithoutType = false;
@Input({ transform: numberAttribute }) requiredWithTransformWithoutType = 1;
@Input() set leaveMeAlone(value: number) {
console.log('setter', value);
Expand Down Expand Up @@ -145,13 +147,15 @@ export class MyCmp {
@Input({ alias: 'defaultAlias' }) withDefaultAlias = 123;
@Input({ alias: 'noDefaultAlias'}) withoutDefaultAlias?: number;
@Input('stringAlias') justAStringAlias = '';
@Input({ transform: booleanAttribute }) withTransform: string | '' = false;
@Input({ transform: booleanAttribute }) withTransform: boolean = false;
@Input({ required: true }) requiredInput!: string;
@Input({ required: true, alias: 'requiredAlias' }) requiredWithAlias!: boolean;
/*
* @description I go with requiredWithAliasAndTransform
*/
@Input({ required: true, alias: 'transformedRequiredAlias', transform: numberAttribute }) requiredWithAliasAndTransform!: string | '';
@Input({ required: true, alias: 'transformedRequiredAlias', transform: numberAttribute }) requiredWithAliasAndTransform!: number;
@Input({ transform: booleanAttribute }) withTransformWithoutType = false;
@Input({ transform: numberAttribute }) requiredWithTransformWithoutType = 1;
@Input() set leaveMeAlone(value: number) {
console.log('setter', value);
Expand Down
4 changes: 4 additions & 0 deletions libs/plugin/src/generators/convert-signal-inputs/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ function getSignalInputInitializer(
}
}

if (transformType) {
types.push('| string');
}

writer.write(types.concat('>').join(''));
}

Expand Down

0 comments on commit 648bfec

Please sign in to comment.