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

chore(TS): minor changes to typescript notation to be compatible with a 5.3.3 #9725

Merged
merged 7 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## [next]

- chore(TS): minor changes to typescript notation to be compatible with a 5.3.3 [#9725](https://github.com/fabricjs/fabric.js/pull/9725)
- ci(): Update the changelog and stats action to work from forks
- fix(Shadow): Cloning a shape with shadow throws an error[#9711](https://github.com/fabricjs/fabric.js/issues/9711)
- chore(TS): use consistent and improved types for getDefaults and ownDefaults [#9698](https://github.com/fabricjs/fabric.js/pull/9698)
Expand Down
199 changes: 0 additions & 199 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,6 @@
"source-map-support": "^0.5.21",
"testem": "^3.8.0",
"tslib": "^2.4.1",
"typedoc": "^0.25.3",
"typedoc-plugin-markdown": "^3.17.0",
"typescript": "^4.9.4",
"v8-to-istanbul": "^9.1.0"
},
Expand Down
16 changes: 12 additions & 4 deletions src/Pattern/Pattern.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,16 +174,24 @@ export class Pattern {
patternWidth =
repeat === 'repeat-y' || repeat === 'no-repeat'
? 1 + Math.abs(patternOffsetX || 0)
: ifNaN((patternSource.width as number) / width, 0),
: ifNaN(
((patternSource as HTMLImageElement).width as number) / width,
0
),
patternHeight =
repeat === 'repeat-x' || repeat === 'no-repeat'
? 1 + Math.abs(patternOffsetY || 0)
: ifNaN((patternSource.height as number) / height, 0);
: ifNaN(
((patternSource as HTMLImageElement).height as number) / height,
0
);

return [
`<pattern id="SVGID_${id}" x="${patternOffsetX}" y="${patternOffsetY}" width="${patternWidth}" height="${patternHeight}">`,
`<image x="0" y="0" width="${patternSource.width}" height="${
patternSource.height
`<image x="0" y="0" width="${
(patternSource as HTMLImageElement).width
}" height="${
(patternSource as HTMLImageElement).height
}" xlink:href="${this.sourceToString()}"></image>`,
`</pattern>`,
'',
Expand Down
4 changes: 2 additions & 2 deletions src/canvas/StaticCanvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1230,11 +1230,11 @@ export class StaticCanvas<
filler.offsetY - finalHeight / 2
}" width="${
(repeat === 'repeat-y' || repeat === 'no-repeat') && isPattern(filler)
? filler.source.width
? (filler.source as HTMLImageElement).width
: finalWidth
}" height="${
(repeat === 'repeat-x' || repeat === 'no-repeat') && isPattern(filler)
? filler.source.height
? (filler.source as HTMLImageElement).height
: finalHeight
}" fill="url(#SVGID_${filler.id})"></rect>\n`
);
Expand Down
4 changes: 2 additions & 2 deletions src/filters/WebGLFilterBackend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,8 @@ export class WebGLFilterBackend {
} else {
const texture = this.createTexture(
this.gl,
textureImageSource.width,
textureImageSource.height,
(textureImageSource as HTMLImageElement).width,
(textureImageSource as HTMLImageElement).height,
textureImageSource,
filter
);
Expand Down
3 changes: 2 additions & 1 deletion src/shapes/Image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,8 @@ export class FabricImage<
ctx: CanvasRenderingContext2D
) {
ctx.imageSmoothingEnabled = this.imageSmoothing;
// @ts-expect-error TS doesn't respect this type casting
// cant use ts-expect-error because of ts 5.3 cross check
// @ts-ignore TS doesn't respect this type casting
super.drawCacheOnCanvas(ctx);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This on the called method would fix the issue without the need of silencing the error:

drawCacheOnCanvas(ctx: CanvasRenderingContext2D) {
    const self = this as TCachedFabricObject;

    ctx.scale(1 / self.zoomX, 1 / self.zoomY);
    ctx.drawImage(
      self._cacheCanvas,
      -self.cacheTranslationX,
      -self.cacheTranslationY
    );
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes me mad that typescript has to error (not warn!!!!) on unused error directives.
So you can silence errors ( dangerous ) but you can't silence error silencers for good code.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not following you. If you use ts-expect-error then I like that it errors if there isn't actually a type error. What you're trying to do with typedoc while keeping the current TS version is not really a common use case for them.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes i know is not common, but is still silly that i cant keep that as a warning and has to block the compilation.

Copy link
Contributor

@jiayihu jiayihu Mar 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does typedoc allow to specify the TS instead? So that it's aligned with fabric

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe. But this is the shortest and more logical path.
No code changes, just annotation changes.
Not fiddling with dependencies of dependencies of astro, just make it run.

}

Expand Down
3 changes: 2 additions & 1 deletion src/shapes/Text/TextSVGExportMixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,8 @@ export class TextSVGExportMixin extends FabricObjectSVGExportMixin {
* @return {String}
*/
getSvgStyles(this: TextSVGExportMixin & FabricText, skipShadow?: boolean) {
// @ts-expect-error TS doesn't respect this type casting
// cant use ts-expect-error because of ts 5.3 cross check
// @ts-ignore TS doesn't respect this type casting
return `${super.getSvgStyles(skipShadow)} white-space: pre;`;
}

Expand Down
Loading
Loading