-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
tsc
fails when using octokit
#2112
Comments
My issue is not that the auto complete doesn't work. My issue is that I get a tsc error that the type doesn't exist when I am compiling it on the command line. |
can you please create a minimal test repository to reproduce the problem? It is probably related to your tsconfig settings or and/or typescript version |
octokit
not exporting proper TypeScript type for octokit
instancetsc
fails when using octokit
The typescript playground is actually telling us why it's failing inside the playground. @neenjaw can you check in your VSCode if you see the same issue/similar issue? Ping me on slack again if you want to work on a repro for Gregor. |
that's great, but it's still a problem with the playground that I cannot reproduce locally. |
Yea, I can make one tonight, will post here with it |
Minimal test repo here: https://github.com/neenjaw/octocat-minimal-issue can recreate |
It wasn't a problem with Octokit, but with the structure of your code. This PR fixes it: Does that work for you? |
It would, can you explain how the previous way caused the |
I wish I could explain it in detail, but I still don't fully understand the inner working of TypeScript myself. And I think there were some changes in type narrowing as part of v4.3. The TypeScript community is very helpful, and there are some very skilled folks looking for TypeScript questions on StackOverflow, if you'd like to ask someone more skilled than myself. I'd also recommend reading https://www.typescriptlang.org/docs/handbook/2/narrowing.html if you haven't yet. |
@gr2m I checked your PR on @neenjaw repro and yes it solves his issue, but I did find the actually issue with the type. The type of Octokit
& void
& { paginate: PaginateInterface }
& Api This results in your PR working because So far, so good, right? The problem is that const octokit = new Octokit({ auth: process.env.GITHUB_TOKEN! })
if (octokit) {
octokit.graphql // nope
} This is understandable behaviour. Something that is if (octokit) {
} else {
octokit.graphql // yep!
} The source export declare const Octokit: typeof OctokitCore & import("@octokit/core/dist-types/types").Constructor<void & {
paginate: import("@octokit/plugin-paginate-rest").PaginateInterface;
} & import("@octokit/plugin-rest-endpoint-methods/dist-types/types").Api>; @neenjaw the reason this worked with earlier versions is that |
can you please open a separate issue for this @SleeplessByte? |
Please avoid duplicates
Reproducible test case
https://www.typescriptlang.org/play?target=6&jsx=0&module=1&strict=true#code/JYWwDg9gTgLgBAbzgeQMYwga2PAvnAMyghDgCIJ0scyAoWgUwA9JY4BDAZwE8A7VQgFd+MYBF6EGMVAAsAFAEpEtOHFTjO8ACrIA0gFEAcnAC8cAOTN24ADYM4GTA17mVajfEqOcpuLwYA7ihU2DBySOyCMDIAXHA6Bsa4Cm7qvJqIcAAm7DDscPhm7AHsPl7UMAB0AOZQ7GAAjjZybqoABq2qcA2CDFDccGCCNjYASgw9DJqccgAkEAH+UHEAyjBQwLzVAIQANHCzUAyQq+ubO-uzvIIgcQCSvPBmAKwADJc27ABGDDaccQBtNYbLbbAC6SgQnS6cCOkE4OGg3DkCyWcXmiz6+141gY6LhEEh0Jhg2GYwmvWmck+Pz+6Jpv04+wIwCgmnR1xA+00uSmcWQAAUjESSaK-BAslNlGKxZyflBiTLRDA7IqxYIoDY1TDcNqCmrdaLDV02rtOlCZai+nFzP5nAArYrmM0ygk2u28R0BVw6twpNxHGAaiQ5PK0XBAA
Please select the environment(s) that are relevant to your bug report
Version
├── [email protected]
What happened?
When compiling with tsc v4.3.2, I receive a type error which I don't see with earlier versions (e.g. 4.1.3), nor do I see it on the TS playground example. The error:
I am able to resolve this by using the
@octokit/graphql
and using the graphql api directly, e.g.:Not sure if the wrong type is being exported?
Would you be interested in contributing a fix?
The text was updated successfully, but these errors were encountered: