diff --git a/package.json b/package.json index 5863626..10fcf7c 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,8 @@ "build": "babel --extensions .ts --ignore '**/*.test.ts' ./src -d dist --source-maps", "test": "jest", "typecheck": "tsc -p . --noEmit", - "prepack": "yarn build" + "prepack": "yarn build", + "typescript2python": "yarn --silent single src/index.ts" }, "bin": { "typescript2python": "./dist/index.js" diff --git a/src/parseInlineType.ts b/src/parseInlineType.ts index 7c4be52..412a97f 100644 --- a/src/parseInlineType.ts +++ b/src/parseInlineType.ts @@ -62,6 +62,10 @@ export const tryToParseInlineType = ( // TODO: figure out why we reach this and replace with correct type definition return `object`; } + } else if (type.flags & TypeFlags.TemplateLiteral) { + // there is no way to represent template literals in Python, + // so we fallback to string + return "str"; } else { // assume interface or object, we need to create a helper type if (!globalScope) { diff --git a/src/parseTypeDefinition.ts b/src/parseTypeDefinition.ts index 85fe8ee..32c4803 100644 --- a/src/parseTypeDefinition.ts +++ b/src/parseTypeDefinition.ts @@ -1,4 +1,4 @@ -import ts from "typescript"; +import ts, { TypeFlags } from "typescript"; import { ParserState } from "./ParserState"; import { getDocumentationStringForDict, parseProperty, parsePropertyForDict } from "./parseProperty"; import { getDocumentationStringForType } from "./getDocumentationStringForType"; diff --git a/src/testing/basic.test.ts b/src/testing/basic.test.ts index c0cd21b..5013350 100644 --- a/src/testing/basic.test.ts +++ b/src/testing/basic.test.ts @@ -62,6 +62,7 @@ describe("transpiling basic types", () => { // without strict mode the `undefined` gets lost here "T = float", ], + ["export type T = `a.b.${string}`", "T = str"], ])("transpiles %p to %p", async (input, expected) => { const result = await transpileString(input); expect(result).toEqual(expected);