canvasimo icon indicating copy to clipboard operation
canvasimo copied to clipboard

Error TS2304: Cannot find name 'Canvas2DContextAttributes'.

Open jkaldon opened this issue 6 years ago • 9 comments

Jake,

I was working on a personal project, Polychromasia, when I ran into the error below. I'm not sure how to address this problem cleanly. Do you have any suggestions?

Thanks,

  • Joshua
Canvasimo Error

jkaldon avatar Mar 12 '19 02:03 jkaldon

Hi, @jkaldon . Can I ask which version of TypeScript you are using, and can you share your tsconfig.json?

JakeSidSmith avatar Mar 12 '19 09:03 JakeSidSmith

Never mind, I can see them. XD It's early.

JakeSidSmith avatar Mar 12 '19 09:03 JakeSidSmith

So, it seems Canvas2DContextAttributes was removed from the standard typescript lib at some point. I'll have to look into this further.

If you add "skipLibCheck": true to your tsconfig.json you should avoid this error.

JakeSidSmith avatar Mar 12 '19 10:03 JakeSidSmith

Okay, seems it was renamed here: https://github.com/Microsoft/TypeScript/commit/ee25cdecbca49b2b5a290ecd65224f425b1d6a9c#diff-46fd87925e4552c166ec188712741c3fR5899

I'll try to update when I have some time. 🙂

JakeSidSmith avatar Mar 12 '19 11:03 JakeSidSmith

Cool, thanks!

In case it matters, here's my project: https://github.com/jkaldon/polychromasia-web

jkaldon avatar Mar 12 '19 21:03 jkaldon

Hey, @jkaldon . Thought I should probably give you an update:

I have fixed the issue, but I can't publish it as there's something wrong with the documentation generation at the moment. I'm looking into this, but I'm a bit stumped - seeking help from the community.

For now a better solution than skipping the lib check might be to add a global alias for the renamed type.

You should be able to put the following in a global type declaration:

type Canvas2DContextAttributes = CanvasRenderingContext2DSettings;

I haven't tried this myself, but in theory it should work nicely. If you're not sure how to do this I'd be happy to fork your repo and open a PR for you. 🙂

JakeSidSmith avatar Apr 16 '19 18:04 JakeSidSmith

Thanks for the update, @JakeSidSmith . For now, I'm content with your skip lib check option until the real fix is possible. I'm not really in any rush.

jkaldon avatar Apr 17 '19 23:04 jkaldon

Just published 0.7.0 which should fix this issue. 😊

JakeSidSmith avatar May 01 '19 20:05 JakeSidSmith

You'll want to npm i [email protected] as I've introduced some new bugs in 0.7.1 and 0.7.2. Oops.

Will be sorting those asap.

JakeSidSmith avatar May 02 '19 08:05 JakeSidSmith