Skip to content

Commit

Permalink
fix: handle more types, close #5
Browse files Browse the repository at this point in the history
  • Loading branch information
so1ve committed Aug 27, 2023
1 parent 705fcc5 commit c3fe6b9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
14 changes: 12 additions & 2 deletions src/core/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,18 @@ export function printVueAcceptableTypeLiteralFromSymbols(
for (const decl of symbol.getDeclarations() ?? []) {
if (ts.isPropertySignature(decl)) {
const type = typeChecker.getTypeAtLocation(decl);
const typeString = typeChecker.typeToString(type);
push(`${decl.name.getText()}: ${toVueAcceptableType(typeString)};`);
const typeString = typeChecker.typeToString(
typeChecker.getBaseTypeOfLiteralType(type),
);
let questionMark = "";
if (decl.questionToken) {
questionMark = "?";
}
push(
`${decl.name.getText()}${questionMark}: ${toVueAcceptableType(
typeString,
)};`,
);
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions test/__fixtures__/a.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import type { A } from "./foo";
defineProps<
{
msg: string;
aaa?: string;
bbb: "a" | "b";
} & A
>();
</script>
4 changes: 3 additions & 1 deletion test/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import type { A } from \\"./foo\\";
defineProps<
{
msg: string;
aaa?: string;
bbb: string;
foo: object;
bar: number;
baz: object;
Expand All @@ -17,7 +19,7 @@ defineProps<
",
"map": SourceMap {
"file": undefined,
"mappings": "AAAA,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACxB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC/B;AACA,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACZ,CAAC;;;;;CAEK;AACN,CAAC,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;",
"mappings": "AAAA,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACxB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC/B;AACA,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACZ,CAAC;;;;;;;CAIK;AACN,CAAC,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;",
"names": [],
"sources": [
"",
Expand Down

0 comments on commit c3fe6b9

Please sign in to comment.