Skip to content

Commit dd5c7ba

Browse files
committed
fix: correctly diff TypeDefs
1 parent 9d6c889 commit dd5c7ba

4 files changed

Lines changed: 149 additions & 22 deletions

File tree

src/diff/ts_type.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub struct TsTypeDiff {
1616

1717
impl TsTypeDiff {
1818
pub fn diff(old: &TsTypeDef, new: &TsTypeDef) -> Option<Self> {
19-
if old.repr == new.repr {
19+
if old == new {
2020
return None;
2121
}
2222

@@ -58,17 +58,9 @@ pub struct TsTypeParamDiff {
5858

5959
impl TsTypeParamDiff {
6060
pub fn diff(old: &TsTypeParamDef, new: &TsTypeParamDef) -> Option<Self> {
61-
let constraint_changed = match (&old.constraint, &new.constraint) {
62-
(Some(old_c), Some(new_c)) => old_c.repr != new_c.repr,
63-
(None, None) => false,
64-
_ => true,
65-
};
61+
let constraint_changed = old.constraint != new.constraint;
6662

67-
let default_changed = match (&old.default, &new.default) {
68-
(Some(old_d), Some(new_d)) => old_d.repr != new_d.repr,
69-
(None, None) => false,
70-
_ => true,
71-
};
63+
let default_changed = old.default != new.default;
7264

7365
if !constraint_changed && !default_changed {
7466
return None;
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# old/mod.ts
2+
export function doc(): Promise<Record<string, Array<DocNode>>> { return {} as any; }
3+
4+
# new/mod.ts
5+
export function doc(): Promise<Record<string, Document>> { return {} as any; }
6+
7+
# output.json
8+
{
9+
"modifiedModules": {
10+
"file:///mod.ts": {
11+
"modified": [
12+
{
13+
"name": "doc",
14+
"declarations": {
15+
"modified": [
16+
{
17+
"kind": "function",
18+
"defChanges": {
19+
"type": "function",
20+
"returnTypeChange": {
21+
"old": {
22+
"repr": "Promise",
23+
"kind": "typeRef",
24+
"value": {
25+
"typeParams": [
26+
{
27+
"repr": "Record",
28+
"kind": "typeRef",
29+
"value": {
30+
"typeParams": [
31+
{
32+
"repr": "string",
33+
"kind": "keyword",
34+
"value": "string"
35+
},
36+
{
37+
"repr": "Array",
38+
"kind": "typeRef",
39+
"value": {
40+
"typeParams": [
41+
{
42+
"repr": "DocNode",
43+
"kind": "typeRef",
44+
"value": {
45+
"typeName": "DocNode"
46+
}
47+
}
48+
],
49+
"typeName": "Array"
50+
}
51+
}
52+
],
53+
"typeName": "Record"
54+
}
55+
}
56+
],
57+
"typeName": "Promise"
58+
}
59+
},
60+
"new": {
61+
"repr": "Promise",
62+
"kind": "typeRef",
63+
"value": {
64+
"typeParams": [
65+
{
66+
"repr": "Record",
67+
"kind": "typeRef",
68+
"value": {
69+
"typeParams": [
70+
{
71+
"repr": "string",
72+
"kind": "keyword",
73+
"value": "string"
74+
},
75+
{
76+
"repr": "Document",
77+
"kind": "typeRef",
78+
"value": {
79+
"typeName": "Document"
80+
}
81+
}
82+
],
83+
"typeName": "Record"
84+
}
85+
}
86+
],
87+
"typeName": "Promise"
88+
}
89+
}
90+
}
91+
}
92+
}
93+
]
94+
}
95+
}
96+
]
97+
}
98+
}
99+
}

0 commit comments

Comments
 (0)