Skip to content

Commit 05fcaf9

Browse files
committed
Emit | undefined types for optional properties/parameters
Previously, the property `a?: string` had the type signature `string`. Now, we emit the more correct type `string | undefined`.
1 parent 593f56d commit 05fcaf9

File tree

5 files changed

+385
-90
lines changed

5 files changed

+385
-90
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
// format-options: showSignatures
22

3-
export type CompletionItemID = string & { _opaque: typeof CompletionItemID }
4-
declare const CompletionItemID: unique symbol
3+
export interface OptionalProperty {
4+
optional1?: string
5+
optional2?: number | null
6+
optional3?: number | undefined
7+
optional4?: undefined
8+
}

snapshots/input/syntax/src/signatures.ts

+7
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ export interface WorkspaceEditParams {
1717
changes: { uri: string }[]
1818
}
1919

20+
export interface OptionalProperty {
21+
optional1?: string
22+
optional2?: number | null
23+
optional3?: number | undefined
24+
optional4?: undefined
25+
}
26+
2027
export interface ExampleSuperInterface<T> {
2128
a: T
2229
b: string

snapshots/output/syntax/src/minimized-signatures.ts

+161-82
Original file line numberDiff line numberDiff line change
@@ -2,86 +2,165 @@
22

33
// format-options: showSignatures
44

5-
export type CompletionItemID = string & { _opaque: typeof CompletionItemID }
6-
// ^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`minimized-signatures.ts`/CompletionItemID#
7-
// info {
8-
// | "symbol": "scip-typescript npm syntax 1.0.0 src/`minimized-signatures.ts`/CompletionItemID#",
9-
// | "documentation": [
10-
// | "```ts\ntype CompletionItemID\n```"
11-
// | ],
12-
// | "relationships": [],
13-
// | "kind": 55,
14-
// | "display_name": "CompletionItemID",
15-
// | "enclosing_symbol": "",
16-
// | "signature": {
17-
// | "type_signature": {
18-
// | "type_parameters": {
19-
// | "symlinks": [],
20-
// | "hardlinks": []
21-
// | },
22-
// | "lower_bound": {
23-
// | "intersection_type": {
24-
// | "types": [
25-
// | {
26-
// | "type_ref": {
27-
// | "symbol": "scip-typescript npm typescript . string#",
28-
// | "type_arguments": []
29-
// | }
30-
// | },
31-
// | {
32-
// | "structural_type": {
33-
// | "declarations": {
34-
// | "symlinks": [
35-
// | "scip-typescript npm syntax 1.0.0 src/`minimized-signatures.ts`/_opaque0:"
36-
// | ],
37-
// | "hardlinks": []
38-
// | }
39-
// | }
40-
// | }
41-
// | ]
42-
// | }
43-
// | }
44-
// | }
45-
// | }
46-
// | }
47-
// ^^^^^^^ definition syntax 1.0.0 src/`minimized-signatures.ts`/_opaque0:
48-
// info {
49-
// | "symbol": "scip-typescript npm syntax 1.0.0 src/`minimized-signatures.ts`/_opaque0:",
50-
// | "documentation": [
51-
// | "```ts\n(property) _opaque: unique symbol\n```"
52-
// | ],
53-
// | "relationships": [],
54-
// | "kind": 41,
55-
// | "display_name": "_opaque",
56-
// | "enclosing_symbol": "",
57-
// | "signature": {
58-
// | "value_signature": {
59-
// | "tpe": {}
60-
// | }
61-
// | }
62-
// | }
63-
// ^^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`minimized-signatures.ts`/CompletionItemID#
64-
// ^^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`minimized-signatures.ts`/CompletionItemID.
65-
declare const CompletionItemID: unique symbol
66-
// ^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`minimized-signatures.ts`/CompletionItemID.
67-
// info {
68-
// | "symbol": "scip-typescript npm syntax 1.0.0 src/`minimized-signatures.ts`/CompletionItemID.",
69-
// | "documentation": [
70-
// | "```ts\nvar CompletionItemID: unique symbol\n```"
71-
// | ],
72-
// | "relationships": [],
73-
// | "kind": 61,
74-
// | "display_name": "CompletionItemID",
75-
// | "enclosing_symbol": "",
76-
// | "signature": {
77-
// | "value_signature": {
78-
// | "tpe": {
79-
// | "type_ref": {
80-
// | "symbol": "scip-typescript npm typescript . symbol#",
81-
// | "type_arguments": []
82-
// | }
83-
// | }
84-
// | }
85-
// | }
86-
// | }
5+
export interface OptionalProperty {
6+
// ^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`minimized-signatures.ts`/OptionalProperty#
7+
// info {
8+
// | "symbol": "scip-typescript npm syntax 1.0.0 src/`minimized-signatures.ts`/OptionalProperty#",
9+
// | "documentation": [
10+
// | "```ts\ninterface OptionalProperty\n```"
11+
// | ],
12+
// | "relationships": [],
13+
// | "kind": 21,
14+
// | "display_name": "OptionalProperty",
15+
// | "enclosing_symbol": "",
16+
// | "signature": {
17+
// | "class_signature": {
18+
// | "type_parameters": {
19+
// | "symlinks": [],
20+
// | "hardlinks": []
21+
// | },
22+
// | "parents": [],
23+
// | "declarations": {
24+
// | "symlinks": [
25+
// | "scip-typescript npm syntax 1.0.0 src/`minimized-signatures.ts`/optional10:",
26+
// | "scip-typescript npm syntax 1.0.0 src/`minimized-signatures.ts`/optional20:",
27+
// | "scip-typescript npm syntax 1.0.0 src/`minimized-signatures.ts`/optional30:",
28+
// | "scip-typescript npm syntax 1.0.0 src/`minimized-signatures.ts`/optional40:"
29+
// | ],
30+
// | "hardlinks": []
31+
// | }
32+
// | }
33+
// | }
34+
// | }
35+
optional1?: string
36+
//^^^^^^^^^ definition syntax 1.0.0 src/`minimized-signatures.ts`/optional10:
37+
// info {
38+
// | "symbol": "scip-typescript npm syntax 1.0.0 src/`minimized-signatures.ts`/optional10:",
39+
// | "documentation": [
40+
// | "```ts\n(property) optional1: string\n```"
41+
// | ],
42+
// | "relationships": [],
43+
// | "kind": 41,
44+
// | "display_name": "optional1",
45+
// | "enclosing_symbol": "",
46+
// | "signature": {
47+
// | "value_signature": {
48+
// | "tpe": {
49+
// | "union_type": {
50+
// | "types": [
51+
// | {
52+
// | "type_ref": {
53+
// | "symbol": "scip-typescript npm typescript . string#",
54+
// | "type_arguments": []
55+
// | }
56+
// | },
57+
// | {
58+
// | "type_ref": {
59+
// | "symbol": "scip-typescript npm typescript . undefined#",
60+
// | "type_arguments": []
61+
// | }
62+
// | }
63+
// | ]
64+
// | }
65+
// | }
66+
// | }
67+
// | }
68+
// | }
69+
optional2?: number | null
70+
//^^^^^^^^^ definition syntax 1.0.0 src/`minimized-signatures.ts`/optional20:
71+
// info {
72+
// | "symbol": "scip-typescript npm syntax 1.0.0 src/`minimized-signatures.ts`/optional20:",
73+
// | "documentation": [
74+
// | "```ts\n(property) optional2: number\n```"
75+
// | ],
76+
// | "relationships": [],
77+
// | "kind": 41,
78+
// | "display_name": "optional2",
79+
// | "enclosing_symbol": "",
80+
// | "signature": {
81+
// | "value_signature": {
82+
// | "tpe": {
83+
// | "union_type": {
84+
// | "types": [
85+
// | {
86+
// | "type_ref": {
87+
// | "symbol": "scip-typescript npm typescript . number#",
88+
// | "type_arguments": []
89+
// | }
90+
// | },
91+
// | {
92+
// | "type_ref": {
93+
// | "symbol": "scip-typescript npm typescript . null#",
94+
// | "type_arguments": []
95+
// | }
96+
// | },
97+
// | {
98+
// | "type_ref": {
99+
// | "symbol": "scip-typescript npm typescript . undefined#",
100+
// | "type_arguments": []
101+
// | }
102+
// | }
103+
// | ]
104+
// | }
105+
// | }
106+
// | }
107+
// | }
108+
// | }
109+
optional3?: number | undefined
110+
//^^^^^^^^^ definition syntax 1.0.0 src/`minimized-signatures.ts`/optional30:
111+
// info {
112+
// | "symbol": "scip-typescript npm syntax 1.0.0 src/`minimized-signatures.ts`/optional30:",
113+
// | "documentation": [
114+
// | "```ts\n(property) optional3: number\n```"
115+
// | ],
116+
// | "relationships": [],
117+
// | "kind": 41,
118+
// | "display_name": "optional3",
119+
// | "enclosing_symbol": "",
120+
// | "signature": {
121+
// | "value_signature": {
122+
// | "tpe": {
123+
// | "union_type": {
124+
// | "types": [
125+
// | {
126+
// | "type_ref": {
127+
// | "symbol": "scip-typescript npm typescript . number#",
128+
// | "type_arguments": []
129+
// | }
130+
// | },
131+
// | {
132+
// | "type_ref": {
133+
// | "symbol": "scip-typescript npm typescript . undefined#",
134+
// | "type_arguments": []
135+
// | }
136+
// | }
137+
// | ]
138+
// | }
139+
// | }
140+
// | }
141+
// | }
142+
// | }
143+
optional4?: undefined
144+
//^^^^^^^^^ definition syntax 1.0.0 src/`minimized-signatures.ts`/optional40:
145+
// info {
146+
// | "symbol": "scip-typescript npm syntax 1.0.0 src/`minimized-signatures.ts`/optional40:",
147+
// | "documentation": [
148+
// | "```ts\n(property) optional4: undefined\n```"
149+
// | ],
150+
// | "relationships": [],
151+
// | "kind": 41,
152+
// | "display_name": "optional4",
153+
// | "enclosing_symbol": "",
154+
// | "signature": {
155+
// | "value_signature": {
156+
// | "tpe": {
157+
// | "type_ref": {
158+
// | "symbol": "scip-typescript npm typescript . undefined#",
159+
// | "type_arguments": []
160+
// | }
161+
// | }
162+
// | }
163+
// | }
164+
// | }
165+
}
87166

0 commit comments

Comments
 (0)