Skip to content

Preserve type aliases in quick info #48666

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

Closed
5 tasks done
mutech opened this issue Apr 13, 2022 · 2 comments
Closed
5 tasks done

Preserve type aliases in quick info #48666

mutech opened this issue Apr 13, 2022 · 2 comments

Comments

@mutech
Copy link

mutech commented Apr 13, 2022

Suggestion

πŸ” Search Terms

List of keywords you searched for before creating this issue. Write them down here so that others can find this suggestion more easily and help provide feedback.

preserve type alias in quick info

βœ… Viability Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

⭐ Suggestion

Preserve type aliases in declarations in quick info of Visual Studio Code instead of replacing them with their definitions.

πŸ“ƒ Motivating Example

I am using type aliases as domain types in order to document their range or meaning, f.e.:

/** Non-negative integer number determining the offset of an item from the first item in a sequence, see {@link isOffset()} */
export type Offset = number

/** Determines whether `candidate` is a valid {@link Offset}.
 *
 * Equivalent to `Number.isSafeInteger(candidate) && candidate >= 0`
 * 
 * @returns `true` if `candidate` is a non-negative safe integer
 */
export function isOffset(candidate: unknown): candidate is Offset { ... }

/** Demonstrates how parameter `offset` does not need additional documentation */
function demo(offset: Offset) { ... }

When looking at the quick info for demo() in Visual Studio Code, the type of the parameter offset is resolved to number. It would be more helpful, if the declared type Offset would be used, especially if it would be a clickable link referring to the type's documentation.

Using domain types in this manner would reduce the necessity to document the range of parameters or the confusion of what numbers would be valid input when documentation is not provided.

The parameter name is often sufficient to document the semantics of such a domain type, but this can only be a hint, while a reference to a domain type can provide a more meaningful/formal definition (as in this example referencing isOffset) and thus more value.

πŸ’» Use Cases

@MartinJohns
Copy link
Contributor

MartinJohns commented Apr 13, 2022

Duplicate of #31940. Used search terms: type alias tooltip in:title

@mutech
Copy link
Author

mutech commented Apr 13, 2022

Looks like my choice of keywords is not sufficiently creative, thanks for the find, Martin

@mutech mutech closed this as completed Apr 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants