@inthedark/dxlint 0.1.14 → 0.1.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/README.md +16 -9
  2. package/bin/dxlint-darwin-arm64 +0 -0
  3. package/bin/dxlint-linux-x64 +0 -0
  4. package/bin/dxlint-win32-x64.exe +0 -0
  5. package/esbuild.mjs +134 -0
  6. package/package.json +20 -2
  7. package/rules/bugs.dx +1 -0
  8. package/std/ts/arithmetic.dx +10 -0
  9. package/std/ts/assertions.dx +56 -4
  10. package/std/ts/calls.dx +45 -15
  11. package/std/ts/conditions.dx +2 -0
  12. package/std/ts/constants.dx +2 -1
  13. package/std/ts/content-mapper.dx +48 -0
  14. package/std/ts/deprecation.dx +38 -18
  15. package/std/ts/effects.dx +8 -1
  16. package/std/ts/enums.dx +32 -4
  17. package/std/ts/format.dx +1 -1
  18. package/std/ts/grammar.dx +29 -15
  19. package/std/ts/import-no-deprecated.dx +4 -2
  20. package/std/ts/javascript.dx +496 -0
  21. package/std/ts/layout/literals.dx +14 -7
  22. package/std/ts/layout/separators.dx +6 -1
  23. package/std/ts/layout/shared.dx +36 -37
  24. package/std/ts/layout/types.dx +4 -0
  25. package/std/ts/literals.dx +1 -0
  26. package/std/ts/methods.dx +3 -0
  27. package/std/ts/modules.dx +60 -2
  28. package/std/ts/names.dx +30 -13
  29. package/std/ts/narrowing.dx +20 -14
  30. package/std/ts/parentheses.dx +27 -0
  31. package/std/ts/problems/control-flow.dx +1 -0
  32. package/std/ts/problems/numeric-precision.dx +1 -0
  33. package/std/ts/problems/regexp.dx +1 -0
  34. package/std/ts/regex/checks.dx +1 -0
  35. package/std/ts/regex/findings.dx +10 -6
  36. package/std/ts/regex/values.dx +4 -15
  37. package/std/ts/restrictions.dx +76 -0
  38. package/std/ts/scoping/member-uses.dx +5 -3
  39. package/std/ts/scoping/shadowing.dx +1 -0
  40. package/std/ts/scoping/usage.dx +3 -3
  41. package/std/ts/spreads.dx +1 -1
  42. package/std/ts/structure/padding.dx +10 -8
  43. package/std/ts/style/expressions.dx +8 -4
  44. package/std/ts/style/returns.dx +3 -1
  45. package/std/ts/style/signatures.dx +5 -0
  46. package/std/ts/style/type-exports.dx +1 -0
  47. package/std/ts/suggestions/builtins.dx +1 -1
  48. package/std/ts/suggestions/comparisons.dx +1 -0
  49. package/std/ts/suggestions/expressions.dx +1 -0
  50. package/std/ts/suggestions/object-spread.dx +1 -1
  51. package/std/ts/tokens.dx +14 -5
  52. package/std/ts/type-specifiers.dx +19 -3
  53. package/std/ts/typed/awaitability.dx +1 -0
  54. package/std/ts/typed/collection-iteration.dx +24 -0
  55. package/std/ts/typed/floating-promises.dx +45 -14
  56. package/std/ts/typed/includes.dx +3 -4
  57. package/std/ts/typed/promises.dx +16 -13
  58. package/std/ts/typed/readonly-parameters.dx +11 -2
  59. package/std/ts/typed/string-boundaries.dx +1 -0
  60. package/std/ts/typed/switches.dx +1 -0
  61. package/std/ts/typed/transfers.dx +54 -7
  62. package/std/ts/typed/type-arguments.dx +19 -20
  63. package/std/ts/typed/type-conversions.dx +1 -0
  64. package/std/ts/typed/type-parameters.dx +1 -1
  65. package/std/ts/typed/using-disposable.dx +98 -0
  66. package/std/ts/typed.dx +22 -9
  67. package/std/ts/values/arguments.dx +1 -1
  68. package/std/ts/values/enums.dx +5 -1
  69. package/std/ts/values/inspection.dx +26 -7
  70. package/std/ts/values.dx +98 -39
  71. package/std/ts.dx +10 -4
@@ -79,21 +79,21 @@ fn type_argument_signature(n) = if n is (ts_call, ts_new) then {
79
79
  value if binding != null && count(binding.choices) == 1 && first(binding.choices).site != null
80
80
  then first(binding.choices) else null
81
81
  } else null
82
- fn type_argument_site(n, signature) = {
83
- value named: type_argument_named(n)
84
- value member: type_argument_member(n)
82
+ group type_argument_owner ts_call, ts_new, ts_type_reference, ts_class, ts_jsx_opening, ts_tagged_template
83
+ in type_argument_owner let type_argument_named_site type_argument_named(node)
84
+ fn type_argument_site(n, signature) = if signature != null then signature.site else {
85
85
  value local: {
86
86
  value declaration: type_argument_local(n)
87
87
  value if declaration != null then node_site(declaration) else null
88
88
  }
89
- value if signature != null then signature.site
90
- else if local != null then local
91
- else if named != null then named
92
- else member
89
+ value if local != null then local else {
90
+ value named: n.type_argument_named_site
91
+ value if named != null then named else type_argument_member(n)
92
+ }
93
93
  }
94
94
  fn type_argument_formals(n, site) = {
95
95
  value formals: if site != null then site_field(n, site, "type_parameter") else null
96
- value named: if formals != null && count(formals) > 0 then null else type_argument_named(n)
96
+ value named: if formals != null && count(formals) > 0 then null else n.type_argument_named_site
97
97
  value if formals != null && count(formals) > 0 then formals
98
98
  else if named != null then site_field(n, named, "type_parameter")
99
99
  else formals
@@ -208,15 +208,6 @@ fn type_argument_same(n, other, widened) = if widened then {
208
208
  value source: value_union(n, [])
209
209
  value source != null && other != null && type_argument_same_handles(source, other)
210
210
  }
211
- fn type_argument_default_site(n, site) = {
212
- value formal: get(type_argument_formals(n, site), count(n.type_argument.nodes) - 1)
213
- value defaults: if formal != null then site_field(n, formal, "default") else null
214
- value if defaults != null && count(defaults) == 1 then first(defaults) else null
215
- }
216
- fn type_argument_default(n, site) = {
217
- value default: type_argument_default_site(n, site)
218
- value if default != null then declaration_value(n, default) else null
219
- }
220
211
  # An unresolved type reference (`F<number>` from a missing module) says
221
212
  # nothing about which arguments it carries; only its written ones can tell
222
213
  # it apart from a default written with another shape.
@@ -278,16 +269,24 @@ fn type_argument_inferred(n, site, signature, formal) = count(n.parent.type_argu
278
269
  && !any(parameters, parameter => parameter != null && parameter != first(pair) && type_argument_mentions(n, parameter, formal))
279
270
  value pair != null && !literal_only && type_argument_same(n, last(pair), true)
280
271
  }
272
+ # A call's argument whose parameter mentions the type parameter infers it:
273
+ # the default then applies only where nothing is written.
274
+ fn type_argument_infers(n, site, signature, formal) = n.parent is (ts_call, ts_new) && {
275
+ value parameters: type_argument_parameter_sites(n, site, signature)
276
+ value any(zip(parameters, n.parent.argument.nodes), pair => pair != null && first(pair) != null && last(pair) != null
277
+ && type_argument_mentions(n, first(pair), formal))
278
+ }
281
279
  fn type_argument_redundancy(n) = {
282
280
  value owner: n.parent.node
283
281
  value arguments: owner.type_argument.nodes
284
282
  value signature: type_argument_signature(owner)
285
283
  value site: type_argument_site(owner, signature)
286
284
  value formal: get(type_argument_formals(owner, site), count(arguments) - 1)
287
- value default: type_argument_default(owner, site)
288
- value default_site: type_argument_default_site(owner, site)
285
+ value defaults: if formal != null then site_field(owner, formal, "default") else null
286
+ value default_site: if defaults != null && count(defaults) == 1 then first(defaults) else null
287
+ value default: if default_site != null then declaration_value(owner, default_site) else null
289
288
  value if last(arguments) != n then null
290
- else if default != null && type_argument_same(n, default, false)
289
+ else if default != null && type_argument_same(n, default, false) && !type_argument_infers(n, site, signature, formal)
291
290
  && (!type_argument_unresolved(n) || type_argument_written_same(n, default_site)) then "default"
292
291
  else if formal != null && type_argument_inferred(n, site, signature, formal) then "inferred"
293
292
  else null
@@ -1,3 +1,4 @@
1
+ import .ts/javascript
1
2
  import .ts/values/inspection
2
3
 
3
4
  define {
@@ -257,7 +257,7 @@ in ts_type_parameter rule es-no-unnecessary-type-parameters warn "Type parameter
257
257
  then type_parameter_owner.end_offset
258
258
  else type_parameter_owner.body.offset ?? type_parameter_owner.return_type.end_offset ?? type_parameter_owner.end_offset
259
259
  let type_parameter_references {
260
- value type_parameter_binding.references
260
+ value name_references(name.node)
261
261
  filter (reference) contains(name_role_classes(reference, "reference"), "type")
262
262
  && reference.offset <= type_parameter_boundary
263
263
  && (reference.offset >= node.end_offset || reference.end_offset <= node.offset)
@@ -0,0 +1,98 @@
1
+ # Disposable values held without `using`.
2
+
3
+ define {
4
+
5
+ # A statement or initializer whose value cannot be an object never reaches a
6
+ # typed question.
7
+ fn using_disposable_primitive(bare) = bare is (ts_null, ts_boolean, ts_number, ts_bigint, ts_string, ts_template, ts_array, ts_arrow, ts_function, ts_regex)
8
+ || bare is ts_update
9
+ || bare is ts_unary && contains(["void", "typeof", "delete", "!", "+", "-", "~"], bare.operator)
10
+ || bare is ts_binary && contains(["<", ">", "<=", ">=", "==", "!=", "===", "!==", "in", "instanceof",
11
+ "+", "-", "*", "/", "%", "**", "&", "|", "^", "<<", ">>", ">>>"], bare.operator)
12
+ || bare is ts_assignment && contains(["+=", "-=", "*=", "/=", "%=", "**=", "<<=", ">>=", ">>>=", "&=", "|=", "^="], bare.operator)
13
+ # An object literal without computed keys or spreads declares only named
14
+ # members, so it cannot carry Symbol.dispose or Symbol.asyncDispose.
15
+ fn using_disposable_plain_object(bare) = bare is ts_object
16
+ && !any(bare.property.nodes, member => member is ts_spread || member.key is ts_computed_key)
17
+ # A method returning its receiver (`server.listen(): this`) hands back a
18
+ # resource its receiver already holds.
19
+ fn using_disposable_returns_receiver(bare) = bare is ts_call && bare.callee is ts_member && {
20
+ value selection: call_selection(bare)
21
+ value selection != null && count(selection.selected) > 0 && all(selection.selected, site =>
22
+ any(site_field(bare, site, "return_type") ?? [], type => site_text(bare, type).text == "this"))
23
+ }
24
+ fn using_disposable_kind(n) = {
25
+ value bare: unparenthesised_node(n)
26
+ value if bare is ts_assignment && bare.operator == "=" then using_disposable_kind(bare.right.node)
27
+ else if bare == null || using_disposable_primitive(bare) || using_disposable_plain_object(bare) then null else {
28
+ value kind: if !(n could object) then null
29
+ else if value_has_member(n, {global: "Symbol", class: "value", path: ["asyncDispose"]}, null) == true then "async"
30
+ else if value_has_member(n, {global: "Symbol", class: "value", path: ["dispose"]}, null) == true then "sync" else null
31
+ value if kind == null || using_disposable_returns_receiver(bare) then null else kind
32
+ }
33
+ }
34
+ in ts_node let using_disposable_held using_disposable_kind(node)
35
+ # Iterators inherit dispose only from the bare lib `Disposable` interface;
36
+ # disposing them means nothing.
37
+ fn using_disposable_inherited_by_iterator(n, key) = value_has_member(n, "next", null) == true && {
38
+ value lookup: value_lookup(n, key)
39
+ value lookup != null && all(lookup.alternatives, alternative => all(alternative.sources, source =>
40
+ source.site != null && contains(["Disposable", "AsyncDisposable"], site_parent(n, source.site).name)))
41
+ }
42
+ # Ownership moves when the value leaves the function or goes into something
43
+ # that outlives it, so `using` would dispose a live resource. An argument stays
44
+ # borrowed: only `new` takes ownership.
45
+ fn using_disposable_carriers(read) = {
46
+ value read
47
+ walk (current) if current.parent is (ts_parenthesized, ts_as, ts_satisfies, ts_non_null, ts_type_assertion, ts_logical, ts_array) || (current.parent is ts_conditional && current.parent.test.node != current) then current.parent.node else null
48
+ }
49
+ fn using_disposable_leaves(carrier) = when {
50
+ carrier.parent is (ts_new, ts_return, ts_yield, ts_property) then true
51
+ carrier.parent is ts_arrow then carrier.parent.body.node == carrier
52
+ carrier.parent is ts_assignment then carrier.parent.right.node == carrier && carrier.parent.left is ts_member
53
+ else then false
54
+ }
55
+ fn using_disposable_aliases(binding) = {
56
+ value binding.references
57
+ flat_map (read) using_disposable_carriers(read)
58
+ map (carrier) when {
59
+ carrier.parent is ts_assignment && carrier.parent.right.node == carrier then carrier.parent.left.declaration
60
+ carrier.parent is ts_declarator && carrier.parent.init.node == carrier && carrier.parent.name is ts_identifier then carrier.parent.name.node
61
+ else then null
62
+ }
63
+ filter (alias) alias != null
64
+ }
65
+ fn using_disposable_escapes(binding) = binding != null && {
66
+ value binding
67
+ walk (current) using_disposable_aliases(current)
68
+ any (current) any(current.references, read => any(using_disposable_carriers(read), carrier => using_disposable_leaves(carrier)))
69
+ }
70
+ fn using_disposable_stored(assignment) = assignment.left is ts_member || using_disposable_escapes(assignment.left.declaration)
71
+ fn using_disposable_declared(initializer) = {
72
+ value kind: using_disposable_kind(initializer)
73
+ value if kind == null then null
74
+ else if using_disposable_inherited_by_iterator(initializer, {global: "Symbol", class: "value", path: [if kind == "async" then "asyncDispose" else "dispose"]}) then null
75
+ else kind
76
+ }
77
+ in ts_declarator let using_disposable_initializer {
78
+ value kind: using_disposable_declared(init.node)
79
+ value if kind != null && !using_disposable_escapes(name) then kind else null
80
+ }
81
+
82
+ in ts_declarator.name rule es-use-using-disposable:declare {
83
+ when !re_test(ts_variable_declaration.kind.text ?? "", /using/) && parent.using_disposable_initializer != null
84
+ # `using` cannot bind a pattern: destructuring drops the resource itself.
85
+ warn when {
86
+ node is ts_identifier && parent.using_disposable_initializer == "async" then "Async disposable resources should be declared with `await using`."
87
+ node is ts_identifier then "Disposable resources should be declared with `using`."
88
+ parent.using_disposable_initializer == "async" then "Async disposable resources should be held with `await using` before destructuring."
89
+ else then "Disposable resources should be held with `using` before destructuring."
90
+ }
91
+ }
92
+ in ts_expression_statement.expression rule es-use-using-disposable:hold {
93
+ let held_assignment unparenthesised_node(node)
94
+ when using_disposable_held != null && !(held_assignment is ts_assignment && using_disposable_stored(held_assignment))
95
+ warn if using_disposable_held == "async" then "Async disposable resources should be held with `await using`." else "Disposable resources should be held with `using`."
96
+ }
97
+
98
+ }
package/std/ts/typed.dx CHANGED
@@ -11,6 +11,7 @@ import .ts/typed/errors
11
11
  import .ts/typed/awaitability
12
12
  import .ts/typed/optional-chains
13
13
  import .ts/typed/floating-promises
14
+ import .ts/typed/using-disposable
14
15
  import .ts/typed/unbound-method
15
16
  import .ts/typed/template-expressions
16
17
  import .ts/typed/readonly-members
@@ -37,6 +38,7 @@ import .ts/typed/enums
37
38
  import .ts/typed/qualifiers
38
39
  import .ts/typed/regexp-exec
39
40
  import .ts/typed/for-in-arrays
41
+ import .ts/typed/collection-iteration
40
42
  import .ts/typed/type-conversions
41
43
  import .ts/typed/rejection-handlers
42
44
  import .ts/typed/unsafe-members
@@ -48,12 +50,16 @@ define {
48
50
 
49
51
  fn generated_empty_type(n) = {
50
52
  value arms: value_parts(n)
51
- value arms != null && any(arms, arm =>
52
- count(arm.parts) > 0 && all(arm.parts, part =>
53
+ value arms != null && any(arms, arm => {
54
+ # An intersection node kept as its own part (`T & {}`) adds no members.
55
+ value concrete: filter(arm.parts, part => part.traits != ["intersection"])
56
+ value handles: if count(concrete) == count(arm.parts) then [arm.handle] else map(concrete, part => part.handle)
57
+ value count(concrete) > 0 && all(concrete, part =>
53
58
  contains(part.traits, "structural") && count(part.uncertain_traits) == 0
54
59
  && part.carrier_known && part.carrier == null)
55
- && value_children(arm.handle, true, []) == []
56
- && value_signatures(arm.handle) == [[]] && value_constructors(arm.handle) == [[]])
60
+ && all(handles, handle => value_children(handle, true, []) == []
61
+ && value_signatures(handle) == [[]] && value_constructors(handle) == [[]])
62
+ })
57
63
  }
58
64
  in ts_type_reference, ts_intersection rule es-no-generated-empty-object-type {
59
65
  when node is ts_intersection || count(type_argument.nodes) > 0
@@ -185,7 +191,9 @@ fn stringification_ignored_alias(n, ignored) = {
185
191
  value roots: value_sources(n)
186
192
  value sites: walk(if count(roots.sites) == 1 then roots.sites else [], site =>
187
193
  if count(site_sources(n, site).sites) == 1 then site_sources(n, site).sites else [])
188
- value arms != null && all(arms, arm => all(arm.parts, part => part.carrier_known && part.carrier == null))
194
+ # TypeScript keeps an alias's name for unions and structural shapes, not
195
+ # for a lone class or interface (`type ClassAlias = Plain` reads as `Plain`).
196
+ value arms != null && (count(arms) > 1 || all(arms, arm => all(arm.parts, part => part.carrier_known && part.carrier == null)))
189
197
  && any(sites, site => site.kind == "ts_type_alias" && contains(ignored, site.name))
190
198
  }
191
199
  fn stringification_part(n, part, ignored, check_unknown, seen) = {
@@ -464,15 +472,20 @@ in ts_call.argument rule es-await-thenable:iterable {
464
472
  when parent.is_promise_aggregator == true && not ts_array && ts_await_nonawaitable_iterable(node)
465
473
  warn "Unexpected iterable of non-Promise (non-\"Thenable\") values passed to promise aggregator."
466
474
  }
475
+ # No arm declares `Symbol[name]` (an open library interface leaves
476
+ # value_has_member undecided, though its declarations lack the member).
477
+ fn typed_lacks_symbol(n, name) = value_has_member(n, {global: "Symbol", class: "value", path: [name]}, null) == false || {
478
+ value key: ts_value_symbol_key(n, name)
479
+ value arms: if key == null then null else value_lookup(n, key).alternatives
480
+ value arms != null && count(arms) > 0 && all(arms, arm => arm.matched == false)
481
+ }
467
482
  in ts_for_of rule es-await-thenable:for-of {
468
483
  report at { start: offset, end: last(overlapping(ts_close_paren, right.end_offset, body.offset)).end_offset }
469
- when contains([] modifier, "await")
470
- && value_has_member(right.node, {global: "Symbol", class: "value", path: ["asyncIterator"]}, null) == false
484
+ when contains([] modifier, "await") && typed_lacks_symbol(right.node, "asyncIterator")
471
485
  warn "Unexpected `for await...of` of a value that is not async iterable."
472
486
  }
473
487
  in ts_declarator.init rule es-await-thenable:using {
474
- when starts_with(parent.parent.kind.text, "await")
475
- && value_has_member(node, {global: "Symbol", class: "value", path: ["asyncDispose"]}, null) == false
488
+ when starts_with(parent.parent.kind.text, "await") && typed_lacks_symbol(node, "asyncDispose")
476
489
  warn "Unexpected `await using` of a value that is not async disposable."
477
490
  }
478
491
 
@@ -4,7 +4,7 @@ define {
4
4
 
5
5
  in ts_identifier {
6
6
  let ts_value_implicit_arguments ts_arguments_owner(node) != null
7
- when ts_value_implicit_arguments {
7
+ when text == "arguments" && ts_value_implicit_arguments {
8
8
  unwraps instance "IArguments"
9
9
  widens instance "IArguments"
10
10
  }
@@ -1,3 +1,4 @@
1
+ import .ts/javascript
1
2
  define {
2
3
 
3
4
  fn ts_value_has_enum(n) = any(value_constituents(n) ?? [], arm => any(arm, part => contains(part.traits, "enum")))
@@ -17,6 +18,7 @@ fn ts_value_enum_prior(n) = {
17
18
  }
18
19
  }
19
20
  in ts_enum {
21
+ let ts_value_enum_plain all(member.nodes, item => item.init == null)
20
22
  let ts_value_enum_literals {
21
23
  value members: member.nodes
22
24
  value states: {
@@ -71,6 +73,7 @@ in ts_enum_member {
71
73
  declares member name keyed ts_value_key(it) in nearest statics hoisted
72
74
  let ts_value_enum_literal if init != null then ts_value_enum_literal(init.node)
73
75
  else if node_ordinal(node) == 0 then 0
76
+ else if parent.ts_value_enum_plain then node_ordinal(node)
74
77
  else get(parent.ts_value_enum_literals, node_ordinal(node))
75
78
  let ts_value_enum_prior ts_value_enum_prior(node)
76
79
  let ts_value_enum_kind when {
@@ -97,7 +100,8 @@ in ts_enum_member {
97
100
  in ts_qualified_name {
98
101
  arguments parent.type_argument
99
102
  let ts_value_qualified_key ts_value_key(right.node)
100
- defines (scope module, namespace from left.definition).[ts_value_qualified_key] ?? (scope statics from left.definition).[ts_value_qualified_key]
103
+ # `import Alias = ns.E; Alias.Zero`: the alias stands for what it defines.
104
+ defines (scope module, namespace from left.definition).[ts_value_qualified_key] ?? (scope statics from left.definition).[ts_value_qualified_key] ?? (scope module, namespace from left.definition.definition).[ts_value_qualified_key] ?? (scope statics from left.definition.definition).[ts_value_qualified_key]
101
105
  unwraps definition
102
106
  }
103
107
 
@@ -1,9 +1,6 @@
1
1
  define {
2
2
 
3
- fn ts_value_has_trait(n, trait) = {
4
- value arms: value_trait_parts(n, [trait])
5
- value if arms == null then null else any(arms, arm => any(arm.parts, part => contains(part.traits, trait)))
6
- }
3
+ fn ts_value_has_trait(n, trait) = value_has_trait(n, trait)
7
4
  fn ts_value_has_void(n) = ts_value_has_trait(n, "void")
8
5
  fn ts_value_callable(n) = {
9
6
  value signatures: value_signatures(n)
@@ -71,7 +68,8 @@ fn ts_value_print_part(part) = {
71
68
  value args: if carrier.description.kind == "tuple" && part.product_known && part.product != null then
72
69
  map(zip(carrier.arguments ?? [], part.product.elements), pair => {
73
70
  value flags: last(pair)
74
- value (if flags.repeated then "..." else "") ts_value_print(first(pair)) (if flags.optional then "?" else "")
71
+ value element: ts_value_print(first(pair))
72
+ value if flags.optional then "(" element " | undefined)?" else if flags.values then "..." element "[]" else element
75
73
  })
76
74
  else map(carrier.arguments ?? [], item => ts_value_print(item))
77
75
  value joined: { value args; join ", " }
@@ -116,12 +114,27 @@ fn ts_value_print_member(edge, seen) = {
116
114
  || any(edge.member.sources, source => source.flags == null) then "unknown"
117
115
  else "{prefix}{name}{optional}: {result};"
118
116
  }
117
+ # A single call signature prints as its function type: `<T>(v: T) => T`.
118
+ fn ts_value_print_signature(n, header, seen) = {
119
+ value formals: map(site_field(n, header.site, "type_parameter") ?? [], formal => site_text(n, first(site_field(n, formal, "name") ?? [])).text)
120
+ value names: map(site_field(n, header.site, "parameter") ?? [], parameter => site_text(n, first(site_field(n, parameter, "name") ?? [])).text)
121
+ value types: map(header.parameters, parameter => ts_value_print_handle_seen(parameter, seen))
122
+ value params: zip(names, types, (name, text) => "{name}: {text}")
123
+ value generics: if count(formals) > 0 then "<" {value formals; join ", "} ">" else ""
124
+ value generics "(" {value params; join ", "} ") => " ts_value_print_handle_seen(header.result, seen)
125
+ }
126
+ fn ts_value_print_callable(part, seen) = if part.carrier != null || !contains(part.traits, "callable") then null else {
127
+ value headers: flat_map(value_signatures(part.handle) ?? [], arm => arm)
128
+ value if count(headers) == 1 then ts_value_print_signature(last(seen), first(headers), seen) else null
129
+ }
119
130
  fn ts_value_print_handle_part(part, seen) = {
120
131
  value structural: part.carrier == null && contains(part.traits, "structural")
121
132
  && !contains(part.traits, "callable") && !contains(part.traits, "constructible")
122
133
  value children: if structural then value_children(part.handle, true, []) else null
123
134
  value members: map(children ?? [], edge => ts_value_print_member(edge, seen))
124
- value if !structural then ts_value_print(value_constituents(part.handle))
135
+ value callable: ts_value_print_callable(part, seen)
136
+ value if callable != null then callable
137
+ else if !structural then ts_value_print(value_constituents(part.handle))
125
138
  else if children == null then "unknown"
126
139
  else if count(children) == 0 then "{{}}"
127
140
  else "{{ " {value members; join " "} " }}"
@@ -143,7 +156,13 @@ fn ts_value_print_handle_seen(n, seen) = {
143
156
  value if arms == null then "unknown" else if count(arms) == 0 then "never"
144
157
  else {value ranked; sort_by (pair) pair.rank; map (pair) pair.label; unique; join " | "}
145
158
  }
146
- fn ts_value_print_handle(n) = ts_value_print_handle_seen(n, [])
159
+ # A plain (argument-free) written reference keeps its name: tsc keeps alias names
160
+ # for object-literal aliases, but expands instantiated conditional aliases.
161
+ fn ts_value_print_handle(n) = {
162
+ value annotation: ts_value_print_annotation(n)
163
+ value plain: annotation is ts_type_reference && count(annotation.type_argument.nodes) == 0
164
+ value if plain then ts_value_print_written(n) ?? ts_value_print_handle_seen(n, []) else ts_value_print_handle_seen(n, [])
165
+ }
147
166
  # The type TypeScript prints for an expression: a type parameter stands for its
148
167
  # constraint (`any` counts as `unknown`), and a reference keeps its written name.
149
168
  fn ts_value_print_annotation(n) = if n is ts_identifier && name_binding(n) != null