Conditionally adding a property in TypeScript -


i'd conditionally add property object (or maybe mean class - unsure of actual semantics in typescript).

import imetadata './metadata-interface';  export default class metadata {      [idx: string]: imetadata;      public 'foo' = {         name: 'foo',     } imetadata;      public 'bar' = {         name: 'bar',     } imetadata; }; 

but how conditionally add bar object? can like:

export default class metadata {      [idx: string]: imetadata;      public 'foo' = {         name: 'foo',     } imetadata;      if(condition) {       public 'bar' = {           name: 'bar',       } imetadata;     } }; 

use if statement:

export default class metadata {      [idx: string]: imetadata;      public 'foo' = {         name: 'foo',     } imetadata;      public 'bar'?: imetadata;      constructor(condition: boolean) {         if (condition) {             this.bar = {                 name: 'bar',             };         }     } } 

Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -