In postcss/autoprefixer, we need to set grid option only if Internet Explorer 10-11 supports.

grid (false|"autoplace"|"no-autoplace"): should Autoprefixer add IE 10-11 prefixes for Grid Layout properties?

What if we do not know in advance, which browser will be supported? In below TypeScript code, we need to compute isSomeVersionOfInternetExplorerSupported. We can check supportedBrowsers array inside code (could be any valid value of browserslist property of browserslist package, e. g. last 1 version, not dead, etc.), however do not know this array elements in advance.

class BroserslistHelper {

  private supportedBrowsers: Array<string>;

  constructor(supportedBrowsers: Array<string>) {
    this.supportedBrowsers = supportedBrowsers;    
  }

  get autoprefixerSetitngs: autoprefixer.Options {
     return {
       browsers: this.supportedBrowsers,
       grid: this.isSomeVersionOfInternetExplorerSupported ? 'autoplace' : false
     }
  }

  get isSomeVersionOfInternetExplorerSupported(): boolean {

      let someVersionOfInternetExplorerSupported = false;

      this.supportedBrowsers.forEach( (browser: string) => {
          // we need to compute is something ...
      })

      return someVersionOfInternetExplorerSupported;
  }
}

If Internet Explorer explicitly has been set in array (ie), it will be simple, but what if we have only browsers like >5%, cover 99.5%, not dead, etc.?

0 Answers