-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add some types to helpers.segment.ts #1
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
base: master
Are you sure you want to change the base?
Conversation
src/helpers/helpers.segment.ts
Outdated
| * @private | ||
| */ | ||
| export function _computeSegments(line, segmentOptions) { | ||
| export function _computeSegments(line: LineElement, segmentOptions: any) { |
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.
Как типизировать SegmentOptions? @dangreen
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.
наверное надо сначала перевести на ts helpers.config.js, так как там эта тема с контекстами
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.
ну тогда пока просто SegmentStyle получается
src/types/index.d.ts
Outdated
| start: number; | ||
| end: number; | ||
| loop: boolean; | ||
| style?: AnyObject; |
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.
Segment.style - я добавил как AnyObject, но может есть вариант более конкретный? Вроде в readStyle как раз такой объект описывается, но я не уверен. @dangreen
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.
function readStyle(options) {
return {
backgroundColor: options.backgroundColor,
borderCapStyle: options.borderCapStyle,
borderDash: options.borderDash,
borderDashOffset: options.borderDashOffset,
borderJoinStyle: options.borderJoinStyle,
borderWidth: options.borderWidth,
borderColor: options.borderColor
};
}
там вот эти пропсы скорей всего
src/helpers/helpers.segment.ts
Outdated
| * @private | ||
| */ | ||
| export function _boundSegments(line, bounds) { | ||
| export function _boundSegments(line: LineElement, bounds: Bounds) { |
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.
Типы Point и PointElement, в LineElement используется первый, но из кода вроде получается, что должен быть второй. @dangreen
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.
да, там PointElement, надо поправить
|
И хотел спросить, как типизировать приватные поля, которые начинаются с "_", например |
src/types/index.d.ts
Outdated
| _loop: boolean; | ||
| _fullLoop: boolean; | ||
| _datasetIndex: number; | ||
| _chart: AnyObject; |
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.
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.
@Arantiryo Да
src/helpers/helpers.canvas.ts
Outdated
| * @private | ||
| */ | ||
| export function _measureText(ctx, data, gc, longest, string) { | ||
| export function _measureText(ctx: CanvasRenderingContext2D, data, gc, longest: number, string) { |
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.
@dangreen Дэн, не нашел в коде, что конкретно туда передается, можешь подсказать?
src/helpers/helpers.canvas.ts
Outdated
| */ | ||
| export function _longestText(ctx, font, arrayOfThings, cache) { | ||
| // eslint-disable-next-line complexity | ||
| export function _longestText<T>(ctx: CanvasRenderingContext2D, font, arrayOfThings: T[], cache) { |
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.
@dangreen Как лучше типизировать arrayOfThings? И с кэшем не совсем понятно, что делать.
src/helpers/helpers.canvas.ts
Outdated
| * @private | ||
| */ | ||
| export function _steppedLineTo(ctx, previous, target, flip, mode) { | ||
| export function _steppedLineTo(ctx: CanvasRenderingContext2D, previous: Point, target: Point, flip, mode) { |
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.
@dangreen flip не нашел типы для mode, подскажи, плиз
src/helpers/helpers.canvas.ts
Outdated
| } | ||
|
|
||
| function drawBackdrop(ctx, opts) { | ||
| function drawBackdrop(ctx: CanvasRenderingContext2D, opts: BackdropOptions) { |
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.
@dangreen вроде бы параметры типизированы корректно, но в строке ctx.fillStyle = opts.color; ошибка несоответствия типов.
src/helpers/helpers.canvas.ts
Outdated
| * @param {*} rect Bounding rect | ||
| */ | ||
| export function addRoundedRectPath(ctx, rect) { | ||
| export function addRoundedRectPath(ctx: CanvasRenderingContext2D, rect: RoundedRect) { |
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.
@dangreen Здесь вроде бы тоже с типами понятно, но ругается на тип radius, хотя должно быть все ок на первый взгляд
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.
Property 'topLeft' does not exist on type 'CornerRadius'.
Property 'topLeft' does not exist on type 'number'.ts(2339)
|
@Arantiryo а зачем ты тут канвас переводишь на TS? тут же мы только segment делаем плюс я уже сделал канвас chartjs#11100 |
|
Справедливо, надо было сначала. с тобой посоветоваться, что дальше делать. Я начал Тогда я откачу последний коммит. Здесь остался #1 (comment) неразрешенный только, но он завязан на |
dangreen
left a comment
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.
сделай плиз откат канваса
| _loop: boolean; | ||
| _fullLoop: boolean; | ||
| _datasetIndex: number; | ||
| _chart: Chart; | ||
| } |
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.
они наверное private?
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.
То есть их нужно убрать из типа? Просто тогда ТС при их использовании начинает ругаться, что такого свойства нет.
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.
я имел в виду модифигатор private
но ладно, оставляй как есть
src/types/index.d.ts
Outdated
| start: number; | ||
| end: number; | ||
| loop: boolean; | ||
| style?: LineOptions['segment']; |
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.
вынеси это в интерфейс SegmentStyle, и его везде используй
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.
Готово 👍
src/helpers/helpers.segment.ts
Outdated
| * @private | ||
| */ | ||
| export function _computeSegments(line, segmentOptions) { | ||
| export function _computeSegments(line: LineElement, segmentOptions: any) { |
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.
ну тогда пока просто SegmentStyle получается
src/helpers/helpers.segment.ts
Outdated
| /** | ||
| * @typedef { import('../elements/element.line.js').default } LineElement | ||
| * @typedef { import('../elements/element.point.js').default } PointElement | ||
| * @typedef {{start: number, end: number, loop: boolean, style?: any}} Segment | ||
| */ |
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.
надо тоже на ts переделать или убрать
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.
Убрал
src/helpers/helpers.segment.ts
Outdated
| interface Bounds { | ||
| property: string; | ||
| start: number; | ||
| end: number; | ||
| } |
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.
перенеси в файл с типами, мб как то SegmentBounds назвать лучше
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.
Готово
src/types/index.d.ts
Outdated
| backgroundColor: Scriptable<Color|undefined, ScriptableLineSegmentContext>, | ||
| borderColor: Scriptable<Color|undefined, ScriptableLineSegmentContext>, | ||
| borderCapStyle: Scriptable<CanvasLineCap|undefined, ScriptableLineSegmentContext>; | ||
| borderDash: Scriptable<number[]|undefined, ScriptableLineSegmentContext>; | ||
| borderDashOffset: Scriptable<number|undefined, ScriptableLineSegmentContext>; | ||
| borderJoinStyle: Scriptable<CanvasLineJoin|undefined, ScriptableLineSegmentContext>; | ||
| borderWidth: Scriptable<number|undefined, ScriptableLineSegmentContext>; |
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.
| backgroundColor: Scriptable<Color|undefined, ScriptableLineSegmentContext>, | |
| borderColor: Scriptable<Color|undefined, ScriptableLineSegmentContext>, | |
| borderCapStyle: Scriptable<CanvasLineCap|undefined, ScriptableLineSegmentContext>; | |
| borderDash: Scriptable<number[]|undefined, ScriptableLineSegmentContext>; | |
| borderDashOffset: Scriptable<number|undefined, ScriptableLineSegmentContext>; | |
| borderJoinStyle: Scriptable<CanvasLineJoin|undefined, ScriptableLineSegmentContext>; | |
| borderWidth: Scriptable<number|undefined, ScriptableLineSegmentContext>; | |
| backgroundColor: Scriptable<Color | undefined, ScriptableLineSegmentContext>, | |
| borderColor: Scriptable<Color | undefined, ScriptableLineSegmentContext>, | |
| borderCapStyle: Scriptable<CanvasLineCap | undefined, ScriptableLineSegmentContext>; | |
| borderDash: Scriptable<number[] | undefined, ScriptableLineSegmentContext>; | |
| borderDashOffset: Scriptable<number | undefined, ScriptableLineSegmentContext>; | |
| borderJoinStyle: Scriptable<CanvasLineJoin | undefined, ScriptableLineSegmentContext>; | |
| borderWidth: Scriptable<number | undefined, ScriptableLineSegmentContext>; |
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.
Поправил
|
@dangreen Дэн, еще есть ошибка |
|
@Arantiryo для всего файла правило отключи |
src/helpers/helpers.segment.ts
Outdated
| * @param {object} [bounds] | ||
| * @param {string} bounds.property - the property of a `PointElement` we are bounding. `x`, `y` or `angle`. | ||
| * @param {number} bounds.start - start value of the property | ||
| * @param {number} bounds.end - end value of the property |
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.
из jsdoc надо типы убрать кстати
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.
@dangreen убрал типы, оставил только описания
This reverts commit a6ea376.
| * @param {object} segment | ||
| * @param {number} segment.start - start index of the segment, referring the points array | ||
| * @param {number} segment.end - end index of the segment, referring the points array | ||
| * @param {boolean} segment.loop - indicates that the segment is a loop | ||
| * @param {object} [segment.style] - segment style | ||
| * @param {PointElement[]} points - the points that this segment refers to | ||
| * @param {object} [bounds] | ||
| * @param {string} bounds.property - the property of a `PointElement` we are bounding. `x`, `y` or `angle`. | ||
| * @param {number} bounds.start - start value of the property | ||
| * @param {number} bounds.end - end value of the property | ||
| * @private |
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.
нужно было удалить только типы, описания аргументов нужно оставить
src/helpers/helpers.segment.ts
Outdated
| * @return {Segment[]} | ||
| * @param line | ||
| * @param segmentOptions | ||
| * @return Segment[] |
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.
тут и ниже видимо ошибся, просто удали строчки "@return Segment[]" раз там описания нет
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.
и можешь делать пр
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.
@dangreen Сделал, спасибо!
No description provided.