I have an object:
const options = {};
and I want to add fields base on another object. if they false I don't want to add this key to the object.
right now I write my code like this:
const options = {};
if (foo.nullable) options.nullable = true;
if (foo.baz) options.baz = true;
if (foo.bar) options.bar = true;
...
if I write like this I get the nullable
key anyway. no matter if is true or false and I want only if true
the key should exist.
const options = { nullable: options.nullable }
// options = { nullable: ... }
So I asking is there a way to write this in better in typescript? something like:
const options = { nullable && options.nullable } // should be options = {} if nullable is false. otherwise is options = { nullable: true }