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

Update the TypeScript Type definitions for canvas-txt 4.0 #85

Closed
codeBelt opened this issue Aug 29, 2023 · 7 comments
Closed

Update the TypeScript Type definitions for canvas-txt 4.0 #85

codeBelt opened this issue Aug 29, 2023 · 7 comments

Comments

@codeBelt
Copy link

The current TypeScript definition is for canvas-txt 3.0. Please update the type definitions to match the 4.0 version.

@geongeorge
Copy link
Owner

@codeBelt do you have @types/canvas-txt installed?

@pratheekbhandary
Copy link

pratheekbhandary commented Sep 4, 2023

@geongeorge seems like its not updated in a while. https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/canvas-txt/index.d.ts

Till then @codeBelt you could declare your own types

declare module 'canvas-txt' {
  export { drawText, splitText, getTextHeight };
}

function drawText(
  ctx: CanvasRenderingContext2D,
  myText: string,
  inputConfig: CanvasTextConfig,
);

function splitText(args: SplitTextArgs): string[];

function getTextHeight(args: TextHeightArgs): number;

interface CanvasTextConfig {
  width: number;
  height: number;
  x: number;
  y: number;
  debug?: boolean;
  align?: 'left' | 'center' | 'right';
  vAlign?: 'top' | 'middle' | 'bottom';
  fontSize?: number;
  fontWeight?: string;
  fontStyle?: string;
  fontVariant?: string;
  font?: string;
  lineHeight?: number;
  justify?: boolean;
}

interface SplitTextArgs {
  ctx: CanvasRenderingContext2D;
  text: string;
  justify: boolean;
  width: number;
}

interface TextHeightArgs {
  ctx: CanvasRenderingContext2D;
  text: string;
  style: string;
}

Sorry forgot to thank all the contributors for this handy library 🙂

@geongeorge
Copy link
Owner

geongeorge commented Sep 4, 2023

@pratheekbhandary Shouldn't this work out of the box if you simply uninstall @types/canvas-txt Because now the lib is now fully typed?
cc: @codeBelt

@pratheekbhandary
Copy link

Yea I noticed that. But for some reason, its not picking up the types for me, hence I had to manually declare it.

@pratheekbhandary
Copy link

Not an expert at this, but can the minification cause issues?
I don't see any types here.
image
image
image

@geongeorge
Copy link
Owner

Thanks @pratheekbhandary I believe this PR should resolve this #86

Vite removes all the type definitions. I added a vite plugin named vite-plugin-dts but couldn't get it working. tsup seems like a good option

@geongeorge
Copy link
Owner

This is now fixed in v4.1.1 (I had to play around with a few versions to get it right. Finally did a minor version change. but feel free to update. nothing should break from 4.0)

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants