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

Use `arguments[paramIndex]` for `ObjectPattern`'s #179

Closed kungfooman closed 2 weeks ago

kungfooman commented 2 weeks ago

Example:

/**
 * @param {PretrainedOptions} [something] Optional parameters.
 */
export async function test(
  {
    revision = 'main',
  } = {}
) {
  return revision;
}
const ret = test();
console.log('ret', ret);

Transpiled code:

/**
 * @param {PretrainedOptions} [something] Optional parameters.
 */
function test({
  revision = 'main',
} = {}) {
  if (!inspectType(something, {
    "type": "PretrainedOptions",
    "optional": true
  }, 'test', 'something')) {
    youCanAddABreakpointHere();
  }
  return revision;
}
const ret = test();
console.log('ret', ret);

Current error:

Uncaught ReferenceError: something is not defined
    at test (<anonymous>:10:20)
    at <anonymous>:18:13