forked from TheLartians/TypeScript2Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelperTypes.test.ts
More file actions
47 lines (35 loc) 路 1.05 KB
/
Copy pathhelperTypes.test.ts
File metadata and controls
47 lines (35 loc) 路 1.05 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
39
40
41
42
43
44
45
46
47
import { transpileString } from "./utils";
describe("creating helper types", () => {
it("converts nested types to helper types", async () => {
const result = await transpileString(`
export type T = { inner: { foo: { bar: string } } }
`);
expect(result).toEqual(
`from typing_extensions import TypedDict
class Ts2PyHelperType2(TypedDict):
bar: str
class Ts2PyHelperType1(TypedDict):
foo: Ts2PyHelperType2
class T(TypedDict):
inner: Ts2PyHelperType1`,
);
});
it("reuses identical helper types", async () => {
const result = await transpileString(`
export type A = { a: { foo: { bar: string } } }
export type B = { b: { foo: { bar: string } } }
export type C = { foo: { bar: string } }
`);
expect(result).toEqual(`from typing_extensions import TypedDict
class Ts2PyHelperType2(TypedDict):
bar: str
class Ts2PyHelperType1(TypedDict):
foo: Ts2PyHelperType2
class A(TypedDict):
a: Ts2PyHelperType1
class B(TypedDict):
b: Ts2PyHelperType1
class C(TypedDict):
foo: Ts2PyHelperType2`);
});
});