From 1c9c2593cdbd333a3c9e4ab9b37c64fa6a27e1b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20=C3=98in=C3=A6s=20Myrseth?= Date: Sun, 19 Jan 2020 01:02:13 +0100 Subject: [PATCH] schema: Avoid distribution of conditional type 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: https://github.com/Microsoft/TypeScript/issues/29368#issuecomment-453529532 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'> ) } } --- src/schema/nodes.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/schema/nodes.ts b/src/schema/nodes.ts index 8cae1a8..5c006d2 100644 --- a/src/schema/nodes.ts +++ b/src/schema/nodes.ts @@ -74,7 +74,7 @@ export class Root extends Node { this.addChild(new class extends Node { serialize() { return `\ -type Configify = T extends object +type Configify = [T] extends [object] ? { [P in keyof T]: Configify; } & Gettable & Listenable : Gettable & Settable & Listenable;`; }