Skip to content

Commit

Permalink
schema: Avoid distribution of conditional type
Browse files Browse the repository at this point in the history
Conditional types are distributed across all types of a union. This is
not what we want in the case of Config. Distribution happens only over
"naked" type parameters and so wrapping the type in a 1-tuple as well as
the check type avoids this behavior. See:

microsoft/TypeScript#29368 (comment)

Before this change, the type of leaf nodes would resolve to:

{
  Bluetooth: {
    Allowed: (
      Gettable<'False'> & Settable<'False'> & Listenable<'False'>
    ) | (
      Gettable<'True'> & Settable<'True'> & Listenable<'True'>
    )
  }
}

whereas what we want is:

{
  Bluetooth: {
    Allowed: (
      Gettable<'False' | 'True'> &
      Settable<'False' | 'True'> &
      Listenable<'False' | 'True'>
    )
  }
}
  • Loading branch information
Martin Øinæs Myrseth committed Jan 19, 2020
1 parent 7517b85 commit 1c9c259
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/schema/nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export class Root extends Node {
this.addChild(new class extends Node {
serialize() {
return `\
type Configify<T> = T extends object
type Configify<T> = [T] extends [object]
? { [P in keyof T]: Configify<T[P]>; } & Gettable<T> & Listenable<T>
: Gettable<T> & Settable<T> & Listenable<T>;`;
}
Expand Down

0 comments on commit 1c9c259

Please sign in to comment.