Skip to content

Commit

Permalink
feat: add support for string mapping types
Browse files Browse the repository at this point in the history
  • Loading branch information
bc-m committed Sep 10, 2023
1 parent 3cdfce3 commit 195874f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
4 changes: 4 additions & 0 deletions lib/plugin/utils/ast-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ export function isStringLiteral(type: Type) {
return hasFlag(type, TypeFlags.StringLiteral) && !type.isUnion();
}

export function isStringMapping(type: Type) {
return hasFlag(type, TypeFlags.StringMapping);
}

export function isNumber(type: Type) {
return hasFlag(type, TypeFlags.Number);
}
Expand Down
5 changes: 3 additions & 2 deletions lib/plugin/utils/plugin-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import {
isInterface,
isNumber,
isString,
isStringLiteral
isStringLiteral,
isStringMapping
} from './ast-utils';

export function getDecoratorOrUndefinedByNames(
Expand Down Expand Up @@ -65,7 +66,7 @@ export function getTypeReferenceAsString(
if (isBigInt(type)) {
return { typeName: BigInt.name, arrayDepth };
}
if (isString(type) || isStringLiteral(type)) {
if (isString(type) || isStringLiteral(type) || isStringMapping(type)) {
return { typeName: String.name, arrayDepth };
}
if (isPromiseOrObservable(getText(type, typeChecker))) {
Expand Down
8 changes: 8 additions & 0 deletions test/plugin/fixtures/project/cats/classes/cat.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,12 @@ export class Cat {
enum: LettersEnum;

enumArr: LettersEnum;

uppercaseString: Uppercase<string>;

lowercaseString: Lowercase<string>;

capitalizeString: Capitalize<string>;

uncapitalizeString: Uncapitalize<string>;
}
6 changes: 5 additions & 1 deletion test/plugin/fixtures/serialized-meta.fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ export default async () => {
enumArr: {
required: true,
enum: t['./cats/dto/pagination-query.dto'].LettersEnum
}
},
uppercaseString: { required: true, type: () => String },
lowercaseString: { required: true, type: () => String },
capitalizeString: { required: true, type: () => String },
uncapitalizeString: { required: true, type: () => String }
}
}
],
Expand Down

0 comments on commit 195874f

Please sign in to comment.