Ask for help to parse a piece of export function makeMap code together.

export function makeMap (
  str: string,
  expectsLowerCase?: boolean  
): (key: string) => true | void {
  const map = Object.create(null)
  const list: Array<string> = str.split(",")
 for (let i = 0; i < list.length; iPP) {
    map[list[i]] = true
  }
  return expectsLowerCase
    ? val => map[val.toLowerCase()]
    : val => map[val]
}

clipboard.png

this is a piece of es6 code "()" followed by ":" what does it mean? is there such a way to write es6?
seek the Great God

Mar.17,2021

this is written in typescript, which means the type of return value. Typescript is a superset of es6 and has strong typing function,

the general meaning of this code is

defines a function, which has a return value, which is also a function, and then defines the return function, that is, the definition (key: string) = > true after the colon | void

.

Thank you. It was written by ts

.
Menu