Skip to content

Commit

Permalink
Merge pull request #2608 from BC-M/feat/support-string-mappings
Browse files Browse the repository at this point in the history
feat: add support for string mapping types
  • Loading branch information
kamilmysliwiec authored Sep 11, 2023
2 parents 5f3caa1 + 195874f commit 27eb8e2
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 27eb8e2

Please sign in to comment.