forked from TheLartians/TypeScript2Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimports.test.ts
More file actions
38 lines (31 loc) 路 1.06 KB
/
Copy pathimports.test.ts
File metadata and controls
38 lines (31 loc) 路 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { typeScriptToPython } from "../typeScriptToPython";
import { createProject, ts } from "@ts-morph/bootstrap";
describe("transpiling referenced types", () => {
it("can refer to types defined in other files", async () => {
const project = await createProject();
project.createSourceFile("foo.ts", `export type Foo = { foo: number }`);
const barSource = project.createSourceFile(
"bar.ts",
`import {Foo} from './foo';\nexport type Bar = {foo: Foo}`,
);
const program = project.createProgram();
const diagnostics = ts.getPreEmitDiagnostics(program);
if (diagnostics.length > 0) {
throw new Error(
`code compiled with errors: ${project.formatDiagnosticsWithColorAndContext(
diagnostics,
)}`,
);
}
const transpiled = typeScriptToPython(program.getTypeChecker(), [
barSource,
]);
expect(transpiled).toEqual(
`from typing_extensions import TypedDict
class Ts2PyFooHelperType1(TypedDict):
foo: float
class Bar(TypedDict):
foo: Ts2PyFooHelperType1`,
);
});
});