open-props icon indicating copy to clipboard operation
open-props copied to clipboard

Imports not working in TypeScript project.

Open chimp1nski opened this issue 3 years ago • 9 comments

When I am trying to import any of the Props into a TypeScript project,

import sizes from "open-props/src/sizes"

I get a ts(2307) Error: Cannot find module 'open-props/src/sizes' or its corresponding type declarations.


Svelte-kit project, TypeScript version: 4.4.3, target: "es2020",


A workaround I found for this is declaring my own modules for the exports[] in package.json.

open-props.d.ts

declare module "open-props/src/sizes";

I am not sure if this is a problem with OpenProps or TypeScript / SvelteKit. Once I find time, I will try and set it up in a React Project and see what happens there.

chimp1nski avatar Feb 24 '22 12:02 chimp1nski

import sizes from "open-props/src/props.sizes.js"

does that resolve the issue? this way you're referencing a file directly and not leaning on the exports map in package.json.

not sure why declaring the module resolves it tho? the file you're importing is some basic ecma js

thanks for reporting, we'll get ya through it, and maybe i can update the docs to help others in the future

argyleink avatar Feb 24 '22 15:02 argyleink

Unfortunately importing via open-props/src/props.sizes.js doesn't work. I forgot to mention that.

I am getting a different error though: [vite] Internal server error: Missing "./src/props.sizes.js" export in "open-props" package

It actually doesn't really block me since I am not actually using the props in javascript. Was just trying things out.

chimp1nski avatar Feb 25 '22 22:02 chimp1nski

glad you're not blocked, but still a bit disconcerting. are you able to import other props, or all props kinda give you the same issues with missing exports?

argyleink avatar Feb 26 '22 00:02 argyleink

Sizes was just used as example here. I am actually not able to import any props.

I was digging a bit deeper and from what I can see, the index.js in /src is re-exporting the props.xyz.js objects through

const OpenProps = mapToObjectNotation({
  ...Animations,
  ...Sizes,
  ...Colors,
  ...ColorsHSL,
  ...Fonts,
  ...Borders,
  ...Aspects,
  ...Easings,
  ...SVG,
  ...Gradients,
  ...StaticShadows,
  ...Zindex,
});

My guess is that the signature gets lost there since the export of index.js is actually "OpenProps" which then has a signature of (props: any) => any instead of the various props objects.

chimp1nski avatar Mar 01 '22 10:03 chimp1nski

wanna help Open Props ship typings for ts importers?

argyleink avatar Mar 07 '22 05:03 argyleink

Hey, sorry for the late reply. Was rly busy with a project. Sounds really interesting, although I am not too sure if I am the right guy for the job.

I'll have a look at it on the weekend and open a PR if I find a good solution.

chimp1nski avatar Mar 23 '22 17:03 chimp1nski

Interesting! I might look into debugging this and/or helping out with TS typings later this week.

hchiam avatar Mar 29 '22 22:03 hchiam

OK, I think I've got typing to work on my fork of open-props. PR forthcoming.

hchiam avatar Apr 10 '22 22:04 hchiam

Hey folks, sorry for not responding for far too long. I was just too busy with stuff unfortunately.

@hchiam Thanks for stepping in. You are the real MVP here!! I had a quick look over your PR and from what I can tell it's a simple and effective solution! Kudos!

chimp1nski avatar Apr 15 '22 11:04 chimp1nski