Skip to content

Commit 0aa6d6b

Browse files
authored
booleanParams need thenElse too (#1318)
1 parent 53d566c commit 0aa6d6b

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

spec/params/params.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,13 +277,13 @@ describe("Params as CEL", () => {
277277
const booleanExpr = params.defineBoolean("BOOL");
278278
const cmpExpr = params.defineInt("A").cmp("!=", params.defineInt("B"));
279279

280-
expect(booleanExpr.then("asdf", "jkl;").toCEL()).to.equal(
280+
expect(booleanExpr.thenElse("asdf", "jkl;").toCEL()).to.equal(
281281
'{{ params.BOOL ? "asdf" : "jkl;" }}'
282282
);
283-
expect(booleanExpr.then(-11, 22).toCEL()).to.equal("{{ params.BOOL ? -11 : 22 }}");
284-
expect(booleanExpr.then(false, true).toCEL()).to.equal("{{ params.BOOL ? false : true }}");
283+
expect(booleanExpr.thenElse(-11, 22).toCEL()).to.equal("{{ params.BOOL ? -11 : 22 }}");
284+
expect(booleanExpr.thenElse(false, true).toCEL()).to.equal("{{ params.BOOL ? false : true }}");
285285
expect(
286-
booleanExpr.then(params.defineString("FOO"), params.defineString("BAR")).toCEL()
286+
booleanExpr.thenElse(params.defineString("FOO"), params.defineString("BAR")).toCEL()
287287
).to.equal("{{ params.BOOL ? params.FOO : params.BAR }}");
288288
expect(cmpExpr.thenElse("asdf", "jkl;").toCEL()).to.equal(
289289
'{{ params.A != params.B ? "asdf" : "jkl;" }}'

src/params/types.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,15 @@ export class BooleanParam extends Param<boolean> {
452452
return !!process.env[this.name] && process.env[this.name] === "true";
453453
}
454454

455+
/** @deprecated */
455456
then<T extends string | number | boolean>(ifTrue: T | Expression<T>, ifFalse: T | Expression<T>) {
457+
return this.thenElse(ifTrue, ifFalse);
458+
}
459+
460+
thenElse<T extends string | number | boolean>(
461+
ifTrue: T | Expression<T>,
462+
ifFalse: T | Expression<T>
463+
) {
456464
return new TernaryExpression(this, ifTrue, ifFalse);
457465
}
458466
}

0 commit comments

Comments
 (0)