Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inlined twoslash filename tag doesnt seem to be passed through to included snippets #170

Open
oveddan opened this issue May 22, 2024 · 0 comments

Comments

@oveddan
Copy link

oveddan commented May 22, 2024

You can see a full example of this reprod in this repository

Given I have two snippets:

docs/snippets/config.ts:

import { zora } from "viem/chains";
import { http, createPublicClient } from "viem";

export const publicClient = createPublicClient({
  // this will determine which chain to interact with
  chain: zora,
  transport: http(),
});

and another snippet that imports that code at docs/snippets/example.ts:

import { publicClient } from "./config";

console.log(publicClient);

I'm attempting to import both with vocs, and use twoslash but run into issues.

Ideally I can have the markdown look like this:

Screenshot 2024-05-22 at 10 43 31 AM

But this results in a twoslash error:
Cannot find module './config' or its corresponding type declarations.

If I try to add twoslash include instructions to example.ts like:

// @filename: config.ts
// [!include ~/snippets/config.ts]

// @filename: example.ts
// ---cut---
import { publicClient } from "./config";

console.log(publicClient);

I get an error:

example.ts
  [2305] 107 - Module '"./config"' has no exported member 'publicClient'.

If I inline that code, the issue goes away:

Screenshot 2024-05-22 at 10 44 05 AM

It seems like the only way to get the issue to go away while being able to import the file is explicitly setting the external files inline, like:

Screenshot 2024-05-22 at 10 45 12 AM

Would it be possible to pass through the included files from the codegroup to included files?
Or is there another recommended approach for including snippets that include other snippets?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant