Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 24, 2025

The @continuationToken decorator enforced that properties be of type string, preventing nullable types like string | null and rejecting non-string types entirely. This constraint was unnecessarily restrictive for pagination patterns.

Changes

  • packages/compiler/src/lib/paging.ts: Removed validation function from continuationTokenDecorator that enforced string type requirement
  • packages/compiler/test/decorators/paging.test.ts: Added tests covering nullable types, optional properties, and non-string types

Usage

The decorator now accepts any type without validation:

model ListPageInfo {
  @pageItems items: string[];
  
  // Now supported: nullable non-optional
  @continuationToken endCursor: string | null;
  
  // Already worked, still works: optional
  @continuationToken token?: string;
  
  // Now supported: non-string types
  @continuationToken offset: int32;
}

Backward compatible - all existing usage continues to work unchanged.

Original prompt

This section details on the original issue you should resolve

<issue_title>[Bug]: Continuation token must allow nullable non optional fields</issue_title>
<issue_description>### Describe the bug

Currently @continuationToken supports only string type for the field. Like this.

model ListPageInfo {
    startCursor?: string;

    @continuationToken
    endCursor?: string;

    hasNext: boolean;
    hasPrev: boolean;
}

While having optional field is fine, for typescript case, to enforce more consistent typing I prefer to make fields nullable instead, therefore compiler would highlight missing expected nullable field.

Therefore @continuationToken should support more than field optionality way of representing the token which might be or might not be, but the field is always present otherwise.

Reproduction

model ListPageInfo {
    startCursor?: string;

    @continuationToken
    endCursor: string | null;

    hasNext: boolean;
    hasPrev: boolean;
}

decorator gives:
Cannot apply continuationToken decorator to string | null since it is not assignable to stringTypeSpec(decorator-wrong-target)

Checklist

<agent_instructions>Remove the constraint that requires the target property of @continuationToken to be a string and the constraint that requires it to be a required property. Correct any tests and add new tests to verify that an optional property cna be marked with this decorator.</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@timotheeguerin This feels resonable, not sure it should even force it to be a string

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Fix continuation token to support nullable fields Remove type and optionality constraints from @continuationToken decorator Nov 24, 2025
Copilot AI requested a review from markcowl November 24, 2025 19:31
Copilot finished work on behalf of markcowl November 24, 2025 19:31
@pkg-pr-new
Copy link

pkg-pr-new bot commented Nov 25, 2025

Open in StackBlitz

npm i https://pkg.pr.new/microsoft/typespec/@typespec/compiler@9078

commit: dd33b6f

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.

[Bug]: Continuation token must allow nullable non optional fields

2 participants