-
Notifications
You must be signed in to change notification settings - Fork 11.9k
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
fix: add data types passed to constructor to instance properties #11071
Closed
dangreen
wants to merge
1
commit into
chartjs:master
from
TrigenSoftware:fix-instance-types-from-constructor
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,3 +63,51 @@ chart4.data.datasets.push({ | |
type: 'line', | ||
data: [1, 2, 3] | ||
}); | ||
|
||
const chart5 = new Chart('chart', { | ||
data: { | ||
labels: ['1', '2', '3'], | ||
datasets: [{ | ||
type: 'line', | ||
data: [{ | ||
category: '1', | ||
value: 1 | ||
}] | ||
}] | ||
} | ||
}); | ||
|
||
chart5.data.datasets.push({ | ||
type: 'line', | ||
data: [{ | ||
category: '1', | ||
value: 1 | ||
}] | ||
}); | ||
|
||
chart5.config.data.datasets.push({ | ||
type: 'line', | ||
data: [{ | ||
category: '2', | ||
value: 2 | ||
}] | ||
}); | ||
|
||
const dataset = chart5.data.datasets[0]; | ||
// number | Point | [number, number] | BubbleDataPoint | { category: string, value: number } | ||
const datapoint = dataset.data[0]; | ||
|
||
if (typeof datapoint === 'object' && 'category' in datapoint) { | ||
// datapoint: { category: string, value: number } | ||
datapoint.value = 2; | ||
} | ||
|
||
if (dataset.type === 'line') { | ||
// number | Point | { category: string, value: number } | ||
const lineDatapoint = dataset.data[0]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Above, we don't know the dataset type, so the datapoint can be |
||
|
||
if (typeof lineDatapoint === 'object' && 'category' in lineDatapoint) { | ||
// datapoint: { category: string, value: number } | ||
lineDatapoint.value = 2; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is incorrect, this should not return the bubble datapoint
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@LeeLenaleee
Is correct because:
Plus, in a runtime data can be changed in any way
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No because you specify it as a line and that does not have the r prop so it shouldn't suggest it with ts. Also it should not rely on the type being changed at runtime
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@LeeLenaleee anyway, it is a problem with
ChartData
, not with changes from #10963, and it should be fixed in a separate PR.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ChartData was changed in that pr, so I'm not sure how its not related. Afaik we can not achieve same level of detail in the types without templating.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This did work before #10963 so it should either be fixed in this PR or #10963 should be totally reverted.
As you can see in this codesandbox
On line 31 I try to read the r prop and it does not let me because it does not exist
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kurkle
ChartData
interface and other interfaces that are used inChartData
were not changed in that PR@LeeLenaleee
ChartData
is notChartData<"line", number[], string>
. It worked because the data property in that chart.js version is locking for input data types, so in that case datasets with other chart type can't be added, and all tests from this file are failing: https://github.com/TrigenSoftware/Chart.js/blob/97772186316a70add5d5b262489b6409913bf4e3/types/tests/config_types.tsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my oppinion that would be better for now because having the current that you can access bubble datapoint on a line dataset by default is worse in my oppinion