IdoPesok / type-safe-paths

TypeSafePaths is a TypeScript library that provides a type-safe way to manage URL paths and their parameters in a web application. It leverages the power of Zod for schema validation, ensuring that both path parameters and search parameters conform to specified schemas.
MIT License
12 stars 0 forks source link

xported variable 'postsPaths' has or is using name 'TPathRegistryNode' from external module "XXXXX" but cannot be named.ts(4023) #11

Open amiranvarov opened 1 month ago

amiranvarov commented 1 month ago

Hey mate, what you did is pretty awesome work! Very handy tool to use.

I'm struggling with one issue at the moment where typescript is complaining with error "Exported variable 'postsPaths' has or is using name 'TPathRegistryNode' from external module "/Users/xxxxxxxxxx/node_modules/type-safe-paths/dist/index" but cannot be named.ts(4023)", not sure if this is a bug or something. Can you share your thoughts?

image

Here is the code of the whole file:

import z from "zod"
import { TypeSafePaths, createPathHelpers,  } from "type-safe-paths"

// Create a new instance of TypeSafePaths with a metadata schema
const paths = new TypeSafePaths({
    metadataSchema: z.object({
        allowedPermissions: z.array(z.enum(["user", "admin"])),
        mustBeLoggedIn: z.boolean(),
    }),
})
    // Add the first path with metadata and search parameters
    .add("/posts/details/:postId", {
        metadata: {
            allowedPermissions: ["admin"],
            mustBeLoggedIn: true,
        },
        searchParams: z.object({
            query: z.string().optional(),
        }),
    })
    // Add a nested path with different metadata and search parameters
    .add("/posts/details/:postId/:commentId", {
        metadata: {
            allowedPermissions: ["user"],
            mustBeLoggedIn: false,
        },
        searchParams: z.object({
            query: z.string().default("hello world"),
            optional: z.string().default("the parsing worked"),
        }),
    })

export const postsPaths = createPathHelpers(paths);

I'm not sure why it's happening.

For context, my typescript version is 5.5.2.

Would really appreciate your help!

amiranvarov commented 1 month ago

if I understand correctly, it should be enough just adding export somewhere in ur lib ?

image