Skip to content

Commit d18cd8b

Browse files
author
Martin Øinæs Myrseth
committed
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: 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'> ) } }
1 parent 2388acf commit d18cd8b

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/schema/nodes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export class Root extends Node {
7474
this.addChild(new class extends Node {
7575
serialize() {
7676
return `\
77-
type Configify<T> = T extends object
77+
type Configify<T> = [T] extends [object]
7878
? { [P in keyof T]: Configify<T[P]>; } & Gettable<T> & Listenable<T>
7979
: Gettable<T> & Settable<T> & Listenable<T>;`;
8080
}

test/schema/__snapshots__/nodes.spec.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export interface Listenable<T> {
2727
once(handler: (value: T) => void): void;
2828
}
2929
30-
type Configify<T> = T extends object
30+
type Configify<T> = [T] extends [object]
3131
? { [P in keyof T]: Configify<T[P]>; } & Gettable<T> & Listenable<T>
3232
: Gettable<T> & Settable<T> & Listenable<T>;
3333

0 commit comments

Comments
 (0)