MattIPv4 - :WaveDoggo: I think this might be a ...
:Wave_Doggo: I think this might be a Zod Q at this point rather than TypeScript itself -- I have a custom type that relies on
import()
types. I've figured out how to partially preserve them when generating declaration files, but I'm still getting some unknown
s included instead of references to the import()
types.Solution:Jump to solution
Ahah!
```ts
type ImagePng = (typeof import(".png"))["default"];
type ImageJpg = (typeof import(".jpg"))["default"];...
16 Replies
TS Playground - An online editor for exploring TypeScript and JavaS...
The Playground lets you write TypeScript or JavaScript online in a safe and sharable way.
Unknown User•3w ago
Message Not Public
Sign In & Join Server To View
Yah, the schema works, but if you try to z.infer from it, it doesn't work (updated my example link as I'd pasted one w/o the infer)
Unknown User•3w ago
Message Not Public
Sign In & Join Server To View
For one of our usages they'll be URLs, for the other they'll be objects
Hence wanting the type to propagate through from the imports correctly, so the end type is correct where we're using it
Unknown User•3w ago
Message Not Public
Sign In & Join Server To View
The objects are a known type we set via module augmentation
Writing custom CI/CD to implement my own version of type-checking sounds like an incredibly complex solution, unless I'm not following
Fwiw, the workaround is just to do
z.infer<typeof ambassadorImageSchema> & { src: ImageImport };
, but I'd really rather z.infer
just work correctlyUnknown User•3w ago
Message Not Public
Sign In & Join Server To View
These aren't JSON, I'm not sure where JSON comes into this at all?
Unknown User•3w ago
Message Not Public
Sign In & Join Server To View
They are images being imported
And so a bundler of some type is going to process them
What that bundler is and what it returns for those imports is up to the user of this library
Unknown User•3w ago
Message Not Public
Sign In & Join Server To View
One of our usages uses plain Webpack and returns a string for the file path, the other is Next.js which'll return an object with the file path, width, height, etc.
But really, it could be anything, hence wanting to have this use those
import()
s correctly so that it'll just use whatever type the user of the library has setup in their module augmentationsUnknown User•3w ago
Message Not Public
Sign In & Join Server To View
Solution
Ahah!
Results in:
So I wasn't far off with what I had before manually setting the type for just the src, just needed to set the type manually for the entire schema