kungfooman / RuntimeTypeInspector.js

Checking JSDoc types at runtime for high-quality types - Trust is good, control is better.
MIT License
8 stars 0 forks source link

Fix literal boolean types #99

Closed kungfooman closed 7 months ago

kungfooman commented 7 months ago

Example:

/**
 * @param {true|false} a
 */
function identity(a) {
  return a;
}
const ret = identity(true);
console.log("ret", ret);

Current output:

/**
 * @param {true|false} a
 */
function identity(a) {
  if (!assertType(a, {
    "type": "union",
    "members": [
      "true",    // this should be simply: true
      "false"   // this should be simply: false
    ],
    "optional": false
  }, 'identity', 'a')) {
    youCanAddABreakpointHere();
  }
  return a;
}
const ret = identity(true);
console.log("ret", ret);