Skip to content

Comments

Convert punctuateSeries to TypeScript#4351

Open
vtejasri1511-sudo wants to merge 1 commit intoflarum:2.xfrom
vtejasri1511-sudo:ts-one-file-3533
Open

Convert punctuateSeries to TypeScript#4351
vtejasri1511-sudo wants to merge 1 commit intoflarum:2.xfrom
vtejasri1511-sudo:ts-one-file-3533

Conversation

@vtejasri1511-sudo
Copy link

@vtejasri1511-sudo vtejasri1511-sudo commented Jan 26, 2026

Partially addresses #3533

Changes proposed in this pull request:

  • Converted framework/core/js/src/common/helpers/punctuateSeries from JavaScript to TypeScript.
  • No behavior or API changes intended; this is a small isolated step in the ongoing core JS → TS migration.

Reviewers should focus on:

  • Confirm logic is unchanged (only typing / file extension change).
  • Confirm TS types (mithril Children) are appropriate and build tooling accepts the new .ts file.

Screenshot
N/A (no user-facing change)

@vtejasri1511-sudo vtejasri1511-sudo requested a review from a team as a code owner January 26, 2026 18:07
Copy link
Member

@imorland imorland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good first contribution — the migration is on the right track and the logic is correct. A few things need addressing before merge.

Logic equivalence ✅
The new for loop produces identical output to the original .reduce().slice(0,-1) chain. Both correctly build [item, glue, item, ...] without a trailing glue. The refactor is actually clearer.

Return type concern
trans() with parameters is typed as any[], not Children. The cast as Children on the glue variable silences a type error rather than reflecting the actual types involved. The return type Children on the function itself is fine (it matches the existing .d.ts), but the as Children assertion is a sign the types aren't quite right.

Default parameter
Adding = [] as a default is a minor API change. The existing call sites always pass the array, but it does change the observable signature. Not a blocker, but worth noting.

/**
* Formats a list of strings/nodes to read fluently in the locale.
*/
export default function punctuateSeries(items: Children[] = []): Children {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function-level JSDoc describing the purpose and example has been removed. Since dist-typings is generated from this file, that documentation will be lost for extension authors browsing the .d.ts declarations. Restore the description and @example from the original .js file:

/**
 * The `punctuateSeries` helper formats a list of strings (e.g. names) to read
 * fluently in the application's locale.
 *
 * ```js
 * punctuateSeries(['Toby', 'Franz', 'Dominion']) // Toby, Franz, and Dominion
 * ```
 */

/**
* Formats a list of strings/nodes to read fluently in the locale.
*/
export default function punctuateSeries(items: Children[] = []): Children {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The items parameter has a default of []. The original function required an argument. While defensive, this is a subtle API change — callers passing undefined will now silently get [] back. Since all current call sites pass the array explicitly, consider dropping the default to keep the types tight:

export default function punctuateSeries(items: Children[]): Children {


if (items.length >= 3) {
const glue = app.translator.trans('core.lib.series.glue_text') as Children;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trans() with parameters returns any[] (see Translator.tsx overloads), not Children. The as Children assertion is masking an underlying type mismatch rather than resolving it.

The simplest correct approach is to type glue as any[]:

const glue = app.translator.trans('core.lib.series.glue_text') as any[];

Or, since the translator returns the rendered translation here, you can just use any and let the array push accept it — or keep as Children with a comment explaining why. Either way, a note clarifying the intentional cast would help reviewers.

Copy link
Member

@imorland imorland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good first contribution — the migration is on the right track and the logic is correct. A few things need addressing before merge.

Logic equivalence ✅
The new for loop produces identical output to the original .reduce().slice(0,-1) chain. Both correctly build [item, glue, item, ...] without a trailing glue. The refactor is actually clearer.

Return type concern
trans() with parameters is typed as any[], not Children. The cast as Children on the glue variable silences a type error rather than reflecting the actual types involved. The return type Children on the function itself is fine (it matches the existing .d.ts), but the as Children assertion is a sign the types aren't quite right.

Default parameter
Adding = [] as a default is a minor API change. The existing call sites always pass the array, but it does change the observable signature. Not a blocker, but worth noting.

/**
* Formats a list of strings/nodes to read fluently in the locale.
*/
export default function punctuateSeries(items: Children[] = []): Children {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function-level JSDoc describing the purpose and example has been removed. Since dist-typings is generated from this file, that documentation will be lost for extension authors browsing the .d.ts declarations. Restore the description and @example from the original .js file:

/**
 * The `punctuateSeries` helper formats a list of strings (e.g. names) to read
 * fluently in the application's locale.
 *
 * ```js
 * punctuateSeries(['Toby', 'Franz', 'Dominion']) // Toby, Franz, and Dominion
 * ```
 */


if (items.length >= 3) {
const glue = app.translator.trans('core.lib.series.glue_text') as Children;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trans() with parameters is typed as any[] (see Translator.tsx overloads), not Children. The cast as Children is masking an underlying type mismatch rather than resolving it.

The simplest correct approach is to type glue as any[]:

const glue = app.translator.trans('core.lib.series.glue_text') as any[];

Or keep as Children but add a comment explaining the intentional cast so reviewers understand it's deliberate.

@imorland imorland added this to the 2.0.0-beta.8 milestone Feb 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants