Skip to content

hourCycle option not recognized for Date.toLocaleString #34399

Closed

Description

TypeScript fails to recognize the hourCycle parameter for toLocaleString, documented on MDN.

TypeScript Version: 3.7.0-dev.20191014

Search Terms: toLocaleString, hourCycle

Code: TS2345

const a = (new Date()).toLocaleString('en-US', {hourCycle: 'h24'});
console.log(a);

Expected behavior:
Compiles without error

Actual behavior:

test.ts:1:51 - error TS2345: Argument of type '{ hourCycle: string; }' is not assignable to parameter of type 'DateTimeFormatOptions'.
  Object literal may only specify known properties, and 'hourCycle' does not exist in type 'DateTimeFormatOptions'.

1 const a = (new Date()).toLocaleString('en-US', {hourCycle: 'h24'});
                                                  ~~~~~~~~~~~~~~~~


Found 1 error.

The generated code then runs fine under Node 12 (I think it's not supported below this version) and in browsers and prints the expected output of the date with requested hour cycle.

Playground Link: http://www.typescriptlang.org/play/?ts=Nightly&ssl=1&ssc=50&pln=1&pc=70#code/MYewdgzgLgBAhjAvDAFGApgdxgETldFASiIDooQAZEYOAG3QGUoAnASzAHMUBXMAE3QAzDun4AaGAG8YACxA8WAYQCewBgC4YAclkBGAEzaYAXyIBuIA

Related Issues:
I did not find any.

Activity

  1. BPScott commented on Aug 12, 2021

    @BPScott

    This issue can be closed.

    As of TypeScript 4.2 hourCycle is present on DateTimeFormatOptions - the interface used for the second parameter of toLocaleString - when you target es2020 or include it in your lib.

    This is a TS playground demonstrating that no errors occur if you target es2020

  2. locked as resolved and limited conversation to collaborators on Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: lib.d.tsThe issue relates to the different libraries shipped with TypeScript

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions