fastify-oauth2 icon indicating copy to clipboard operation
fastify-oauth2 copied to clipboard

TypeScript types do not line up with the code examples

Open krlwlfrt opened this issue 9 months ago • 0 comments

Prerequisites

  • [x] I have written a descriptive issue title
  • [x] I have searched existing issues to ensure the bug has not already been reported

Fastify version

5.2.1

Plugin version

8.1.2

Node.js version

23.9.0

Operating system

Linux

Operating system version (i.e. 20.04, 11.3, 10)

Arch Linux

Description

I've noticed that the examples from the readme cause TypeScript errors. See the screenshot of the following code and the resulting errors from tsc.

Image

❯ npx tsc
src/index.ts:69:21 - error TS2339: Property 'access_token' does not exist on type 'OAuth2Token'.

69   console.log(token.access_token)
                       ~~~~~~~~~~~~

src/index.ts:74:81 - error TS2345: Argument of type 'string' is not assignable to parameter of type 'Token'.

74   const newToken = await this.nextcloudOAuth.getNewAccessTokenUsingRefreshToken(refreshToken, {})
                                                                                   ~~~~~~~~~~~~


Found 2 errors in the same file, starting at: src/index.ts:69

Run the following commands in the MRE to reproduce:

npm install
npx tsc

Link to code that reproduces the bug

https://gist.github.com/krlwlfrt/f27b24e753856a2f26b11cd7a2843758

Expected Behavior

Types should not cause errors when using example code from readme. It's confusing and causes me to have to use workarounds to use types and have working code.

krlwlfrt avatar Mar 22 '25 15:03 krlwlfrt