Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
StephanTLavavej opened this issue Feb 6, 2022 · 1 comment · Fixed by #10137
Closed

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

StephanTLavavej opened this issue Feb 6, 2022 · 1 comment · Fixed by #10137
Labels
type: bug type: types Typescript type changes
Milestone

Comments

@StephanTLavavej
Copy link

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

@etimberg
Copy link
Member

etimberg commented Feb 6, 2022

Thanks! This one is interesting since we thought we typed it correctly. https://github.com/chartjs/Chart.js/blob/master/types/index.esm.d.ts#L3179-L3180. it appears the types aren't merging well with the min/max options on CartesianScaleOptions. Should be a simple fix 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug type: types Typescript type changes
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants