microsoft / microsoft/TypeScript

Change Diagnostic.code to 'string | number'

Open
#28,911 3 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Breaking Change Domain: API Experience Enhancement Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

I'm writing a LanguageService plugin for TypeScript that returns custom diagnostics. A Diagnostic needs to have a code property of type number.

I don't have a number. Instead I can provide a string that represents the name of the rule producing the diagnostic. In addition a random number I would choose looks quite ugly in the tooltip VSCode displays for the Diagnostic.

I know TypeScript only ever creates Diagnostics with numeric code, but it's too limiting for plugins.
I looked it up and the LanguageServer protocol specifies it as code?: number | string.

My current workaround is to use a type assertion. Until now nothing bad has happened.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the Diagnostic type and the LanguageService plugin API, then compare the current numeric code requirement with the Language Server Protocol definition mentioned in the issue. Check how diagnostic codes are consumed and displayed, and consider existing numeric diagnostics before determining whether string codes can be accepted without breaking current behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.