Skip to content
This repository has been archived by the owner on May 6, 2023. It is now read-only.

How to publish types? #155

Open
mckelveygreg opened this issue Sep 1, 2022 · 3 comments
Open

How to publish types? #155

mckelveygreg opened this issue Sep 1, 2022 · 3 comments

Comments

@mckelveygreg
Copy link
Contributor

Is there a way to publish the types from the generated schemas? I tried to compile, I get a variation of the following error:

The inferred type of 'headlines' cannot be named without a reference to 'sanity-typed-schema-builder/node_modules/@sanity/types'. This is likely not portable. A type annotation is necessary.

5 export const headlines = s.document({

I found some suggestions like setting "preserveSymlinks": true, but that causes the emitted types files to be anys...

The issue appears to have been added to the Typescript 4.8 milestone... but 4.8 has already been published.

Hoping perhaps that I am missing something silly? I really like this library's pattern, so if we can't get this to work, then I think i'll make a monorepo so I'll have access to the types in our frontend 🤷


tsconfig.json as suggested by sanity docs

{
  // Note: This config is only used to help editors like VS Code understand/resolve
  // parts, the actual transpilation is done by babel. Any compiler configuration in
  // here will be ignored.
  "include": ["./node_modules/@sanity/base/types/**/*.ts", "./**/*.ts", "./**/*.tsx"],
  "compilerOptions": {
    "jsx": "react",
    "esModuleInterop": true
  }
}

tsconfig.schema.json used for actually building

{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "module": "esnext",
    "target": "esnext",
    "skipLibCheck": true,
    "outDir": "./dist_schema/",
    "rootDir": "./app/schema/",
    "moduleResolution": "node",
    "declaration": true,
    "declarationMap": true,
    "declarationDir": "./dist_schema/"
  }
}
@saiichihashimoto
Copy link
Owner

A (temporary) solution is install @sanity/types directly, which will help typescript find this. I'm not sure why having this type as a dependency of this project doesn't work, considering it's being installed. I'd assumed transitive typescript dependencies should work? I must be missing something.

That issue has it added to the 4.8 milestone, but the ticket is still open. It's not done, likely needs to be reprioritized on the Typescript side. I'm not convinced this is the right issue, either.

@mckelveygreg
Copy link
Contributor Author

mckelveygreg commented Sep 2, 2022

Even with @sanity/types installed, it didn't seem to pick them up when I would compile with tsc 🤷
Thanks for leaving a comment on the ts issue!!

@saiichihashimoto
Copy link
Owner

I'm not sure why I suggested that, considering we're not even doing that in our own projects. This will need more investigation. If you're able to make a PR with a solution, that would be amazing!

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

No branches or pull requests

2 participants