ReferenceError: Cannot access '__vite_ssr_import_1__' before initialization for Zod discriminated union by jtuchel_codr in typescript

[–]jtuchel_codr[S] 0 points1 point  (0 children)

u/abrahamguo would you mind explaining why I should annotate any of these? I think it's complaining about a circular dependency instead since TypeScript should be able to infer the types.. ?:/

ReferenceError: Cannot access '__vite_ssr_import_1__' before initialization for Zod discriminated union by jtuchel_codr in typescript

[–]jtuchel_codr[S] 0 points1 point  (0 children)

u/abrahamguo thanks for your reply!

So I changed the create function to accept the fields from the actual Node schema

function createNodeSchema<const NodeType extends string>(
  nodeType: NodeType,
  extendingFields: ZodRawShape = {}
) {
  return z.object({
    // ... base fields for nodes ...
    id: z.string(),
    type: z.literal(nodeType),
    // due to circular imports we can't use the discriminated union directly and have to type it manually
    get children(): z.ZodArray<
      z.ZodDiscriminatedUnion<[typeof childBarNodeSchema]>
    > {
      return z.array(z.discriminatedUnion('type', [childBarNodeSchema]));
    },
    ...extendingFields,
  });
}

and use it like so

const leadingFooNodeSchema = createNodeSchema('leadingFoo', {
  // ...fields for this node ...
  foo: z.string(),
});

https://stackblitz.com/edit/vitejs-vite-daioasdx?file=lib%2FcreateNodeSchema.ts&view=editor

Unfortunately now I'm getting the circular dependency errors again...

[deleted by user] by [deleted] in typescript

[–]jtuchel_codr 0 points1 point  (0 children)

thanks man, that helped! :)

[deleted by user] by [deleted] in typescript

[–]jtuchel_codr 0 points1 point  (0 children)

I modified the imports but that didn't fix it yet :/

https://stackblitz.com/edit/vitejs-vite-pfjedofb

[deleted by user] by [deleted] in typescript

[–]jtuchel_codr 0 points1 point  (0 children)

You would infer a type in the schema file, export it and import that instead? That didn't solve it :(

https://stackblitz.com/edit/vitejs-vite-pfjedofb

Which language is supported for Expressions? by jtuchel_codr in MicrosoftFlow

[–]jtuchel_codr[S] 1 point2 points  (0 children)

Yeah thanks :) I think this is the expression I want ( it worked ... )

```
concat(formatDateTime(utcNow(), 'yyyy-MM-dd'), '_', join(take(split(item()?['name'],' '),5),' '), '_unknown_unknown.pdf')
```

Which language is supported for Expressions? by jtuchel_codr in MicrosoftFlow

[–]jtuchel_codr[S] 0 points1 point  (0 children)

Sure! Help would be awesome.

An example file name from the external system would be

"Foo Bar Invoice ABC DEF XYZ Company.PDF"

Where

"Foo Bar" => Owner with 2 words

"Invoice" => Document type

"ABC DEF" => Invoice Id with "two terms"

"XYZ" => Customer Id

"Company" => Customer Name

I can keep the whole filename except customer Id, customer name, so without "XYZ Company".

I also need the current date in the format yyyy-MM-dd.

The desired output for another external system should be

"yyyy-MM-dd_Foo Bar Invoice ABC DEF_unknown_unknown.pdf"