Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.20.0-beta.24: constraint type parameters results in an error #1408

Closed
runarberg opened this issue Dec 2, 2020 · 2 comments
Closed

0.20.0-beta.24: constraint type parameters results in an error #1408

runarberg opened this issue Dec 2, 2020 · 2 comments
Labels
bug Functionality does not match expectation

Comments

@runarberg
Copy link

Search terms

  • template constraints
  • type parameter extends
  • generic constraints

Expected Behavior

Docs should be generated without errors

Actual Behavior

Docs are not generated with the following error:

Error output
TypeDoc exiting with unexpected error:
AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:

  assert(params.length === 1)

    at Object.convertType (/home/user/src/andcetera/node_modules/typedoc/dist/lib/converter/types.js:96:9)
    at Object.convertType (/home/user/src/andcetera/node_modules/typedoc/dist/lib/converter/types.js:80:34)
    at Converter.convertType (/home/user/src/andcetera/node_modules/typedoc/dist/lib/converter/converter.js:55:24)
    at /home/user/src/andcetera/node_modules/typedoc/dist/lib/converter/factories/signature.js:47:33
    at Array.map (<anonymous>)
    at convertTypeParameters (/home/user/src/andcetera/node_modules/typedoc/dist/lib/converter/factories/signature.js:43:79)
    at Object.createSignature (/home/user/src/andcetera/node_modules/typedoc/dist/lib/converter/factories/signature.js:20:29)
    at Object.convertFunctionOrMethod (/home/user/src/andcetera/node_modules/typedoc/dist/lib/converter/symbols.js:158:39)
    at Object.convertSymbol (/home/user/src/andcetera/node_modules/typedoc/dist/lib/converter/symbols.js:75:79)
    at Converter.convertExports (/home/user/src/andcetera/node_modules/typedoc/dist/lib/converter/converter.js:157:23) {
  generatedMessage: true,
  code: 'ERR_ASSERTION',
  actual: false,
  expected: true,
  operator: '=='
}

Steps to reproduce the bug

Note: I’m using TypeScript in JavaScript, but the bug is also reproducible in TypeScript (i.e. function foo<T extends unknown[]>()):

Write a function that uses a constraint generic type parameter (i.e. @template {Constraint} T):

src/combinators/zip.js

/**
 * Take any number of iterators, and zip them together into one iterator of
 * tuples. Closes after the shortest of the inputs closes.
 *
 * @template {unknown[]} A Tuple type with item type of each input iterator
 * @param {{ [K in keyof A]: Iterable<A[K]> }} items The iterators to be zipped
 * @returns {Iterable<A>}
 */
export default function* zip(...items) {
  const iters = items.map((item) => item[Symbol.iterator]());
  let buffer = iters.map((iter) => iter.next());

  while (!buffer.some(({ done }) => done)) {
    yield /** @type {A} */ (buffer.map(({ value }) => value));

    buffer = iters.map((iter) => iter.next());
  }
}

Try to generate the docs:

npx typecheck src/combinators/zip.js

See the error above.

tsconfig.json

{
  "compilerOptions": {
    "module": "ESNext",
    "target": "ESNext",
    "moduleResolution": "node",
    "allowSyntheticDefaultImports": true,
    "allowJs": true,
    "checkJs": true,
    "strict": true,
    "noEmit": true
  },
  "include": ["src/**/*.js"],
  "typedocOptions": {
    "mode": "library",
    "inputFiles": ["src/index.js"],
    "entryPoint": "index",
    "out": "docs"
  }
}

Environment

  • Typedoc version: 0.20.0-beta.24
  • TypeScript version: 4.1.2
  • Node.js version: v15.1.0
  • OS: Linux Ubuntu 20.10
@runarberg runarberg added the bug Functionality does not match expectation label Dec 2, 2020
@runarberg
Copy link
Author

Possible related to #202

@Gerrit0
Copy link
Collaborator

Gerrit0 commented Dec 5, 2020

This is.... really weird. The assert seems reasonable to me, and most of the time it works properly. The only time it doesn't appears to be when the array is in a constraint of a type parameter. Fixed in beta 25, and I've reached out of to some of the compiler team to see if they can enlighten me as to why an array has more than one type argument...

@Gerrit0 Gerrit0 added this to To do in Version 0.20 via automation Dec 18, 2020
@Gerrit0 Gerrit0 moved this from To do to Done in Version 0.20 Dec 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Functionality does not match expectation
Projects
No open projects
Development

No branches or pull requests

2 participants