Skip to content

fix(types): Type diff note position line numbers as numbers - #3915

Open
pataar wants to merge 1 commit into
jdalrymple:mainfrom
pataar:fix/discussion-position-line-numbers
Open

pataar wants to merge 1 commit into
jdalrymple:mainfrom
pataar:fix/discussion-position-line-numbers

Conversation

@pataar

@pataar pataar commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Problem

DiscussionNotePositionTextSchema types new_line and old_line as strings, but the discussions API returns them as numbers, and as null for the side of the diff a line doesn't exist on. A diff note on an added line comes back as:

{
  "position": {
    "base_sha": "b5d6e7b1613fca24d250fa8e5bc7bcc3dd6002ef",
    "start_sha": "7c9c2ead8a320fb7ba0b4e234bd9529a2614e306",
    "head_sha": "4803c71e6b1833ca72b8b26ef2ecd5adc8a38031",
    "old_path": "package.json",
    "new_path": "package.json",
    "position_type": "text",
    "old_line": null,
    "new_line": 19
  }
}

Observed on every diff note sampled on a self-managed GitLab instance; the docs example shows the same numbers ("old_line": 27, "new_line": 27). The sibling DiscussionNotePositionTextLineSchema (used by line_range) already types these fields as number.

Consumers reading a note's position currently have to cast new_line to number.

Change

new_line?: string; old_line?: string → new_line?: number | null; old_line?: number | null on DiscussionNotePositionTextSchema.

DiscussionNotePositionOptions was derived from this schema with Camelize<>, so a plain edit would also have turned the request option position.newLine into a number and broken every caller passing a string. The text variant's shared fields move to a local DiscussionNotePositionTextBaseSchema, and the options keep their string line numbers on top of it. The request type is unchanged; I checked that the old and new DiscussionNotePositionOptions are identical types.

Types only, no runtime change. Code that reads position.new_line as a string (for example .padStart() or a comparison against a string) is now flagged; it was receiving numbers at runtime already. MergeRequestDraftNotePositionSchema builds on the same union, so draft note positions get the same correction.

The docs example also shows "old_line": null inside line_range.start, so DiscussionNotePositionTextLineSchema is probably nullable too. I left it alone here because the options type still derives from it.

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

Successfully merging this pull request may close these issues.

1 participant