Skip to content

Commit

Permalink
Emit | undefined types for optional properties/parameters
Browse files Browse the repository at this point in the history
Previously, the property `a?: string` had the type signature `string`.
Now, we emit the more correct type `string | undefined`.
  • Loading branch information
olafurpg committed Apr 19, 2024
1 parent 198d8e7 commit 330023d
Show file tree
Hide file tree
Showing 5 changed files with 385 additions and 90 deletions.
8 changes: 6 additions & 2 deletions snapshots/input/syntax/src/minimized-signatures.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
// format-options: showSignatures

export type CompletionItemID = string & { _opaque: typeof CompletionItemID }
declare const CompletionItemID: unique symbol
export interface OptionalProperty {
optional1?: string
optional2?: number | null
optional3?: number | undefined
optional4?: undefined
}
7 changes: 7 additions & 0 deletions snapshots/input/syntax/src/signatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ export interface WorkspaceEditParams {
changes: { uri: string }[]
}

export interface OptionalProperty {
optional1?: string
optional2?: number | null
optional3?: number | undefined
optional4?: undefined
}

export interface ExampleSuperInterface<T> {
a: T
b: string
Expand Down
243 changes: 161 additions & 82 deletions snapshots/output/syntax/src/minimized-signatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,86 +2,165 @@

// format-options: showSignatures

export type CompletionItemID = string & { _opaque: typeof CompletionItemID }
// ^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`minimized-signatures.ts`/CompletionItemID#
// info {
// | "symbol": "scip-typescript npm syntax 1.0.0 src/`minimized-signatures.ts`/CompletionItemID#",
// | "documentation": [
// | "```ts\ntype CompletionItemID\n```"
// | ],
// | "relationships": [],
// | "kind": 55,
// | "display_name": "CompletionItemID",
// | "enclosing_symbol": "",
// | "signature": {
// | "type_signature": {
// | "type_parameters": {
// | "symlinks": [],
// | "hardlinks": []
// | },
// | "lower_bound": {
// | "intersection_type": {
// | "types": [
// | {
// | "type_ref": {
// | "symbol": "scip-typescript npm typescript . string#",
// | "type_arguments": []
// | }
// | },
// | {
// | "structural_type": {
// | "declarations": {
// | "symlinks": [
// | "scip-typescript npm syntax 1.0.0 src/`minimized-signatures.ts`/_opaque0:"
// | ],
// | "hardlinks": []
// | }
// | }
// | }
// | ]
// | }
// | }
// | }
// | }
// | }
// ^^^^^^^ definition syntax 1.0.0 src/`minimized-signatures.ts`/_opaque0:
// info {
// | "symbol": "scip-typescript npm syntax 1.0.0 src/`minimized-signatures.ts`/_opaque0:",
// | "documentation": [
// | "```ts\n(property) _opaque: unique symbol\n```"
// | ],
// | "relationships": [],
// | "kind": 41,
// | "display_name": "_opaque",
// | "enclosing_symbol": "",
// | "signature": {
// | "value_signature": {
// | "tpe": {}
// | }
// | }
// | }
// ^^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`minimized-signatures.ts`/CompletionItemID#
// ^^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`minimized-signatures.ts`/CompletionItemID.
declare const CompletionItemID: unique symbol
// ^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`minimized-signatures.ts`/CompletionItemID.
// info {
// | "symbol": "scip-typescript npm syntax 1.0.0 src/`minimized-signatures.ts`/CompletionItemID.",
// | "documentation": [
// | "```ts\nvar CompletionItemID: unique symbol\n```"
// | ],
// | "relationships": [],
// | "kind": 61,
// | "display_name": "CompletionItemID",
// | "enclosing_symbol": "",
// | "signature": {
// | "value_signature": {
// | "tpe": {
// | "type_ref": {
// | "symbol": "scip-typescript npm typescript . symbol#",
// | "type_arguments": []
// | }
// | }
// | }
// | }
// | }
export interface OptionalProperty {
// ^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`minimized-signatures.ts`/OptionalProperty#
// info {
// | "symbol": "scip-typescript npm syntax 1.0.0 src/`minimized-signatures.ts`/OptionalProperty#",
// | "documentation": [
// | "```ts\ninterface OptionalProperty\n```"
// | ],
// | "relationships": [],
// | "kind": 21,
// | "display_name": "OptionalProperty",
// | "enclosing_symbol": "",
// | "signature": {
// | "class_signature": {
// | "type_parameters": {
// | "symlinks": [],
// | "hardlinks": []
// | },
// | "parents": [],
// | "declarations": {
// | "symlinks": [
// | "scip-typescript npm syntax 1.0.0 src/`minimized-signatures.ts`/optional10:",
// | "scip-typescript npm syntax 1.0.0 src/`minimized-signatures.ts`/optional20:",
// | "scip-typescript npm syntax 1.0.0 src/`minimized-signatures.ts`/optional30:",
// | "scip-typescript npm syntax 1.0.0 src/`minimized-signatures.ts`/optional40:"
// | ],
// | "hardlinks": []
// | }
// | }
// | }
// | }
optional1?: string
//^^^^^^^^^ definition syntax 1.0.0 src/`minimized-signatures.ts`/optional10:
// info {
// | "symbol": "scip-typescript npm syntax 1.0.0 src/`minimized-signatures.ts`/optional10:",
// | "documentation": [
// | "```ts\n(property) optional1: string\n```"
// | ],
// | "relationships": [],
// | "kind": 41,
// | "display_name": "optional1",
// | "enclosing_symbol": "",
// | "signature": {
// | "value_signature": {
// | "tpe": {
// | "union_type": {
// | "types": [
// | {
// | "type_ref": {
// | "symbol": "scip-typescript npm typescript . string#",
// | "type_arguments": []
// | }
// | },
// | {
// | "type_ref": {
// | "symbol": "scip-typescript npm typescript . undefined#",
// | "type_arguments": []
// | }
// | }
// | ]
// | }
// | }
// | }
// | }
// | }
optional2?: number | null
//^^^^^^^^^ definition syntax 1.0.0 src/`minimized-signatures.ts`/optional20:
// info {
// | "symbol": "scip-typescript npm syntax 1.0.0 src/`minimized-signatures.ts`/optional20:",
// | "documentation": [
// | "```ts\n(property) optional2: number\n```"
// | ],
// | "relationships": [],
// | "kind": 41,
// | "display_name": "optional2",
// | "enclosing_symbol": "",
// | "signature": {
// | "value_signature": {
// | "tpe": {
// | "union_type": {
// | "types": [
// | {
// | "type_ref": {
// | "symbol": "scip-typescript npm typescript . number#",
// | "type_arguments": []
// | }
// | },
// | {
// | "type_ref": {
// | "symbol": "scip-typescript npm typescript . null#",
// | "type_arguments": []
// | }
// | },
// | {
// | "type_ref": {
// | "symbol": "scip-typescript npm typescript . undefined#",
// | "type_arguments": []
// | }
// | }
// | ]
// | }
// | }
// | }
// | }
// | }
optional3?: number | undefined
//^^^^^^^^^ definition syntax 1.0.0 src/`minimized-signatures.ts`/optional30:
// info {
// | "symbol": "scip-typescript npm syntax 1.0.0 src/`minimized-signatures.ts`/optional30:",
// | "documentation": [
// | "```ts\n(property) optional3: number\n```"
// | ],
// | "relationships": [],
// | "kind": 41,
// | "display_name": "optional3",
// | "enclosing_symbol": "",
// | "signature": {
// | "value_signature": {
// | "tpe": {
// | "union_type": {
// | "types": [
// | {
// | "type_ref": {
// | "symbol": "scip-typescript npm typescript . number#",
// | "type_arguments": []
// | }
// | },
// | {
// | "type_ref": {
// | "symbol": "scip-typescript npm typescript . undefined#",
// | "type_arguments": []
// | }
// | }
// | ]
// | }
// | }
// | }
// | }
// | }
optional4?: undefined
//^^^^^^^^^ definition syntax 1.0.0 src/`minimized-signatures.ts`/optional40:
// info {
// | "symbol": "scip-typescript npm syntax 1.0.0 src/`minimized-signatures.ts`/optional40:",
// | "documentation": [
// | "```ts\n(property) optional4: undefined\n```"
// | ],
// | "relationships": [],
// | "kind": 41,
// | "display_name": "optional4",
// | "enclosing_symbol": "",
// | "signature": {
// | "value_signature": {
// | "tpe": {
// | "type_ref": {
// | "symbol": "scip-typescript npm typescript . undefined#",
// | "type_arguments": []
// | }
// | }
// | }
// | }
// | }
}

Loading

0 comments on commit 330023d

Please sign in to comment.