Custom Transformer: Imports? #3609
ColoredCarrot
started this conversation in
General
Replies: 3 comments 11 replies
|
@ColoredCarrot Check this example with Big.js. It's the same logic, you need to declare and use a symbol instead of plain Temporal identifier. Let me know if you're unable to figure it out #3132 (comment) |
0 replies
|
@ColoredCarrot something like this should work (didn't test, I'm on mobile) const temporal = plugin.symbolOnce('Temporal', {
external: 'temporal-polyfill',
}); |
10 replies
|
@mrlubos @ColoredCarrot Wondering if its possible to import 2 or more types from a single source? {
typeTransformers: [
({ $, schema, plugin }) => {
if (schema.type === "number") {
const CustomNumber = plugin.symbolOnce("CustomNumber", {
external: "@shared/types",
kind: "type",
});
return $.type(CustomNumber);
}
if (schema.type === "string" && schema.format === "FlakeIdString") {
const temporal = plugin.symbolOnce("FlakeIdString", {
external: "@shared/types",
kind: "type",
});
return $.type(temporal);
}
return undefined;
},
],
name: "@hey-api/transformers",
},But the generated types file have only: import type { FlakeIdString } from "@shared/types";when it should be: import type { FlakeIdString, CustomNumber } from "@shared/types";If I use plugin.symbol instead of import type {
CustomNumber,
CustomNumber2,
CustomNumber3,
FlakeIdString,
} from "@shared/types"; |
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Hi,
I'm attempting to write a custom transformer as introduced in #2281, in order to use JavaScript's new
Temporalinstead ofDate.The TypeScript DSL has drastically changed since that PR, now using
$. I've been able to adapt to that, getting it to generate what I want:The one thing I'm missing now is a way to add an import for
Temporal, since I'm using a polyfill until browser support catches up:How can I add that import?
Here's my transformer so far:
I saw this discussion, but the workaround of an line import won't work for me, since I'm generating runtime code. Which would need to use a dynamic import, which is
async, so can't be used since transformers are sync. (Side note, it would be very nice if transformer functions were declared async.)All reactions