twoslash icon indicating copy to clipboard operation
twoslash copied to clipboard

Compiler errors with `@paths` compiler option

Open vecerek opened this issue 1 year ago • 0 comments

Disclaimer: I'm still new to twoslash. It may be that I'm doing something wrong.

I'm trying to render HTML for the following markdown code with shiki twoslash in a monorepo using TS path aliases:

```ts twoslash title="example.ts"
import { Schema } from "@effect/schema"
import { ULID } from "@myorg/schema-extended"
import { Effect } from "effect"

const decode = Schema.decodeUnknown(ULID)

const program = decode("01HZT9JC9RY11PPAY429ZDZ46X")

void Effect.runPromise(program).then(console.log, console.error)
```

This results in the following error:

Twoslash error: Errors were thrown in the sample, but not included in an errors tag
These errors were not marked as being expected: 2345. 
Expected: // @errors: 2345
Compiler Errors:

index.ts
  [2345] 155 - Argument of type 'brand<typeof ULID, "ULID">' is not assignable to parameter of type 'Schema<unknown, unknown, unknown>'.
  [2345] 239 - Argument of type 'Effect<unknown, ParseError, unknown>' is not assignable to parameter of type 'Effect<unknown, ParseError, never>'.

This can also be reproduced using the twoslash CLI[^1] if the @paths compiler option is inlined in the code example like so:

```ts twoslash title="example.ts"
// @paths: { "@myorg/schema-extended": ["../../packages/schema-extended/src"] }
import { Schema } from "@effect/schema"
import { ULID } from "@myorg/schema-extended"
import { Effect } from "effect"

const decode = Schema.decodeUnknown(ULID)

const program = decode("01HZT9JC9RY11PPAY429ZDZ46X")

void Effect.runPromise(program).then(console.log, console.error)
```

I'm not going to provide the whole context in this issue. I've created the following reproduction repo instead: https://github.com/vecerek/docusaurus-shiki-twoslash-example. You shall find all relevant information (including the precise reproduction steps) in its README.

I think this is a twoslash issue because the TS code compiles correctly outside the documentation, i.e.:

// docs/src/this-compiles.ts
import { Schema } from "@effect/schema"
import { ULID } from "@myorg/schema-extended"
import { Effect } from "effect"

const decode = Schema.decodeUnknown(ULID)

const program = decode("01HZT9JC9RY11PPAY429ZDZ46X")

void Effect.runPromise(program).then(console.log, console.error)

[^1]: It requires a small patch to @typescript/twoslash (also described in the reproduction repo's README) because the current version of twoslash CLI doesn't work with the inlined @paths compiler option

vecerek avatar Oct 20 '24 16:10 vecerek