types for structured diffs
- Dominant language
- TypeScript
- Stars
- 5.5k
- Forks
- 379
- Avg merge
- 2h 8m
- Merged PRs (30d)
- 6
Description
I added these types to [endanger](https://github.com/discord/endanger) I figured you might want them as well
```ts
export interface StructuredDiffBaseChange {
type: "add" | "del" | "normal"
add: true | undefined
del: true | undefined
normal: true | undefined
content: string
}
export interface StructuredDiffAddChange extends StructuredDiffBaseChange {
type: "add"
add: true
del: undefined
normal: undefined
ln: number
}
export interface StructuredDiffDelChange extends StructuredDiffBaseChange {
type: "del"
add: undefined
del: true
normal: undefined
ln: number
}
export interface StructuredDiffNormalChange extends StructuredDiffBaseChange {
type: "normal"
add: undefined
del: undefined
normal: true
ln1: number
ln2: number
}
export type StructuredDiffChange =
| StructuredDiffAddChange
| StructuredDiffDelChange
| StructuredDiffNormalChange
export interface StructuredDiffChunk {
content: string
changes: StructuredDiffChange[]
oldStart: number
oldLines: number
newStart: number
newLines: number
}
export interface StructuredDiff {
chunks: StructuredDiffChunk[]
}
```
Note I did this kind of funky thing with the `add/del/normal` flags on chunk changes so that they would work as tagged unions in TS (i.e. `change.add` refines to `StructuredDiffAddChange`)
```ts
export interface StructuredDiffBaseChange {
// ...
add: true | undefined
del: true | undefined
normal: true | undefined
// ...
}
export interface StructuredDiffAddChange extends StructuredDiffBaseChange {
// ...
add: true
del: undefined
normal: undefined
// ...
}
// etc
```
Contributor guide
Research direction
The issue provides TypeScript definitions for StructuredDiff, its chunks, and tagged change variants, but names no repository files or tests. Search the codebase for the structured-diff representation and existing exported types, then determine where these interfaces belong. Done means consumers can use the proposed types and TypeScript narrowing works for add, del, and normal changes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100