Skip to content

Types: Time scales with string values aren't recognized #10134

@StephanTLavavej

Description

@StephanTLavavej

Expected behavior

I expected TypeScript to accept options: { scales: { x: { type: "time", min: "2021-01-01", max: "2021-12-01" } } }.

Current behavior

Compiler errors:
Type '"time"' is not assignable to type '"timeseries" | undefined'.
Type 'string' is not assignable to type 'number | undefined'.

Reproducible sample

https://www.typescriptlang.org/play?#code/JYWwDg9gTgLgBAbzgYQBYENZwL5wGZQQhwDkAxhrAHQBWAziQNwCwAUKJFuZTPQLToAJujAwAplD7DxfPADsGLVmwA2Y+GRgAPOAF44giGQCuIMXJhUA5uoCiasxYBCATwCSggBQAiEC7SYMN4AlHDodHAAEgAqALIAMsjocgBu4fZijjBKavB+AVj6cmIA7ig8nppaADSIbHBwMC5gYgBccN4qwMXe1fUG6DDo7Qj9DdLh6nTtANpjDXWsC8twKugARmIq7d4ACsBivfPLE7PHK0haOwBMAAzXAIx8t08vvXAu7QDMOH1LK8tLjd7q9rs8Hu9PnAHr9zoC4FcOndHs8vuDIe0ACyw-4AhpApEg56Y9G1KEw7B-PELAneZGvACspI+7QZOOp+IRwJRtwAbMyoQBOdkc2n054AdgF7WuIupYqJtwAHNK4Ly5XiFTzBaq2ZS4TSuYSUQ9bqqfvrcZqjXSiQ9XhCyayNQCtU8HmC3k64EqcAaALpUvHraCCCTICAqaA7ADEt3jCaOVuW63QZAA1lZCMY5III1GoLH4wAxYvx7znbDzf39S0NCCiYAQBQjeZ0MjoNTTRYAxGjZMLJotHYwUCHIMAkDdbkO0kGkDoRG2k2eiGVicLKH96lDtodLrFTBJ6lTuTtW4b5YLxGmyvzKv-B-YYJKIA

Optional extra steps/info to reproduce

Here's a codepen demonstrating that this works at runtime: https://codepen.io/StephanTLavavej/pen/RwjooGY

The Time Cartesian Axis > Date Formats documentation explains how string values are adapted:

When providing data for the time scale, Chart.js uses timestamps defined as milliseconds since the epoch (midnight January 1, 1970, UTC) internally. However, Chart.js also supports all of the formats that your chosen date adapter accepts.

And then it lists min and max as number | string.

Possible solution

No response

Context

I'm converting the microsoft/STL Status Chart, powered by Chart.js, to use TypeScript. 😸

chart.js version

v3.7.0

Browser name and version

Chrome 98.0.4758.81

Link to your project

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions