Skip to content

Commit fed56bc

Browse files
hive-botclaude
andcommitted
fix: keep DocumentStatus.status typed as DocumentStatusCode
Widening the released response type to accept any string breaks callers that assign it to DocumentStatusCode or switch on it exhaustively. The type stays as released; ok() still treats unknown statuses as not failed, so polling continues through them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent cdbbd02 commit fed56bc

5 files changed

Lines changed: 10 additions & 16 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
106106
`updateStyleRuleCustomInstruction(styleId, instructionId, label, prompt, sourceLanguage?)`.
107107

108108
### Changed
109-
- `DocumentStatus.status` is typed as `DocumentStatusCode | string`, so statuses
110-
the API adds later are typed correctly. At runtime the value was already
111-
the string the API returned.
112109
- `Formality`, `SentenceSplittingMode`, `TagHandlingMode`, `TagHandlingVersion`
113110
and `ModelType` accept any string in addition to their listed values, so values
114111
the API adds later can be passed without a type cast.

‎README.md‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -317,10 +317,10 @@ deprecated aliases of these methods and will be removed in the next major
317317
version.
318318

319319
A `DocumentStatus` has `documentId`, `status` (`'queued'`, `'translating'`,
320-
`'done'`, `'error'`, or another string for a status this library does not know
321-
yet), `secondsRemaining`, `billedCharacters` and `errorMessage`. `done()` is
322-
true when the status is `'done'`; `ok()` is true unless the status is
323-
`'error'`, so the polling methods keep waiting through unknown statuses.
320+
`'done'` or `'error'`), `secondsRemaining`, `billedCharacters` and
321+
`errorMessage`. `done()` is true when the status is `'done'`; `ok()` is true
322+
unless the status is `'error'`, so the polling methods keep waiting through
323+
statuses this library does not know.
324324

325325
#### Document translation options
326326

‎src/parsing.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,14 +288,14 @@ class UsageImpl implements Usage {
288288
}
289289

290290
class DocumentStatusImpl implements DocumentStatus {
291-
public status: DocumentStatusCode | (string & Record<never, never>);
291+
public status: DocumentStatusCode;
292292
public secondsRemaining?: number;
293293
public billedCharacters?: number;
294294
public errorMessage?: string;
295295
public documentId?: string;
296296

297297
constructor(
298-
status: DocumentStatusCode | (string & Record<never, never>),
298+
status: DocumentStatusCode,
299299
secondsRemaining?: number,
300300
billedCharacters?: number,
301301
errorMessage?: string,
@@ -541,7 +541,7 @@ export function parseDocumentStatus(json: string): DocumentStatus {
541541
try {
542542
const obj = JSON.parse(json) as DocumentStatusApiResponse;
543543
return new DocumentStatusImpl(
544-
obj.status,
544+
obj.status as DocumentStatusCode,
545545
obj.seconds_remaining,
546546
obj.billed_characters,
547547
obj.error_message,

‎src/types.ts‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -792,11 +792,10 @@ export interface DocumentStatus {
792792
readonly documentId?: string;
793793

794794
/**
795-
* One of the status values defined in DocumentStatusCode, or another string if the API
796-
* returns a status this version of the library does not know.
795+
* One of the status values defined in DocumentStatusCode.
797796
* @see DocumentStatusCode
798797
*/
799-
readonly status: DocumentStatusCode | (string & Record<never, never>);
798+
readonly status: DocumentStatusCode;
800799

801800
/**
802801
* Estimated time until document translation completes in seconds, otherwise undefined if

‎tests/offline/translateDocument.test.ts‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,8 @@ describe('Translator.translateDocumentGetStatus', () => {
213213
nock(serverUrl).post('/v2/document/doc-id', keyBody).reply(200, { status: 'resyncing' });
214214

215215
const status = await makeDeeplClient().translateDocumentGetStatus(handle);
216-
// Compiles only while DocumentStatus.status accepts strings outside DocumentStatusCode.
217-
const expected: deepl.DocumentStatus['status'] = 'resyncing';
218216

219-
expect([status.status, status.ok(), status.done()]).toEqual([expected, true, false]);
217+
expect([status.status, status.ok(), status.done()]).toEqual(['resyncing', true, false]);
220218
});
221219

222220
it('URL-encodes the document ID in the path', async () => {

0 commit comments

Comments
 (0)