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

When function return type is inferred, the displayed signature's return type is missing a type parameter #2079

Closed
reify-thomas-smith opened this issue Oct 18, 2022 · 1 comment
Labels
bug Functionality does not match expectation

Comments

@reify-thomas-smith
Copy link

Search terms

Signature, return type, type parameter

Expected Behavior

Signature should be capitalize<T>(string: T): Capitalize<T>

Actual Behavior

Signature is capitalize<T>(string: T): Capitalize

Steps to reproduce the bug

/**
 * Capitalize the first letter of a string.
 */
export function capitalize<T extends string>(string: T) {
  return (
    string === '' ? '' : string[0].toUpperCase() + string.slice(1)
  ) as Capitalize<T>;
}

The bug does not occur if you add an explicit return type annotation.

Environment

  • Typedoc version: 0.23.17
  • TypeScript version: 4.7.4
  • Node.js version: 16.14.0
  • OS: macOS 12.6
@reify-thomas-smith reify-thomas-smith added the bug Functionality does not match expectation label Oct 18, 2022
@Gerrit0
Copy link
Collaborator

Gerrit0 commented Oct 23, 2022

Deep in typescript.js...

if (type.flags & 268435456 /* TypeFlags.StringMapping */) {
    var typeNode = typeToTypeNodeHelper(type.type, context);
    return symbolToTypeNode(type.symbol, context, 788968 /* SymbolFlags.Type */, [typeNode]);
    //   override type arguments                                                 ^^^^^^^^^^
}

Thanks TS. You do it magically, so just don't bother filling out the typeArguments property for anyone using the compiler API :/

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
None yet
Development

No branches or pull requests

2 participants