bogeychan / elysia-logger

A plugin for Elysia.js for logging using the pino library
https://npmjs.com/package/@bogeychan/elysia-logger
MIT License
112 stars 7 forks source link

Type / tsc issues when using elysia-logger types in Elysia 1.1.6 #22

Open jordanburke opened 2 days ago

jordanburke commented 2 days ago

What versions are running?

"dependencies": { "@bogeychan/elysia-logger": "^0.1.2", "@elysiajs/swagger": "^1.1.1", "elysia": "1.1.16", "pino-pretty": "^11.2.2", }, "devDependencies": { "@typescript-eslint/eslint-plugin": "^8.7.0", "eslint": "^8.37.0", "bun-types": "latest", "prettier": "^3.3.3", "typescript": "^5.6.2" },

What steps can reproduce the bug?

Import and use a type def using Elysia 1.1.6:

import { Logger } from "@bogeychan/elysia-logger/dist/types"

then run:

tsc --noEmit

Also was able to reproduce this in the elysia-logger by upgrading to 1.1.6

What is the expected behavior?

tsc --noEmit

Process finished with exit code 0

What do you see instead?

node_modules/@bogeychan/elysia-logger/src/index.ts:128:13 - error TS2339: Property 'store' does not exist on type 'never'.

128 ctx.store.startTime ??= 0;


node_modules/@bogeychan/elysia-logger/src/index.ts:129:13 - error TS2339: Property 'store' does not exist on type 'never'.

129         ctx.store.endTime = performance.now();

node_modules/@bogeychan/elysia-logger/src/index.ts:130:13 - error TS2339: Property 'store' does not exist on type 'never'.

130 ctx.store.responseTime = ctx.store.endTime - ctx.store.startTime;


node_modules/@bogeychan/elysia-logger/src/index.ts:130:38 - error TS2339: Property 'store' does not exist on type 'never'.

130         ctx.store.responseTime = ctx.store.endTime - ctx.store.startTime;

node_modules/@bogeychan/elysia-logger/src/index.ts:130:58 - error TS2339: Property 'store' does not exist on type 'never'.

130 ctx.store.responseTime = ctx.store.endTime - ctx.store.startTime;



Found 5 errors in the same file, starting at: node_modules/@bogeychan/elysia-logger/src/index.ts:128

Process finished with exit code 2

### Additional information

_No response_
bogeychan commented 22 hours ago

Thanks for reporting this finding!

I can't reproduce it on my end. Please use import type { Logger } from "@bogeychan/elysia-logger/types"; instead of importing from the dist folder.

I'm aware there's a bug with https://github.com/elysiajs/elysia/issues/838 at the moment, but I don't want to break backward compatibility just to fix a type issue I can't reproduce.


Can you provide me some code snipped please? Like how do you use the imported Logger?

jordanburke commented 16 hours ago

Thanks for checking it out! Yeah it's around that - I think I found the issue. I noticed at some point my IDE pulled in:

import { logger } from "@bogeychan/elysia-logger"

as the import instead of

import { logger } from "@bogeychan/elysia-logger/dist"

The former import @bogeychan/elysia-logger is hitting this in the package file types as defined here.

"types": "./src/index.ts",

Not sure what the current standard package solution is here. It looks like the raw types in @bogeychan/elysia-logger are causing my tsc to bomb out even with "skipLibCheck": true on, whereas the tsc compiled /dist types are not. I think because it's looking at the raw index.ts instead of a type file. For now I'll use this import.

import { logger } from "@bogeychan/elysia-logger/dist"

I think if the package changes to a "types": "./dist/index.d.ts", or similar on the top level types (not the export one) - it could potentially fix it as well. I'll give it try later and post back if I get a chance.

Hope that helps - functionally-wise it works great though.

bogeychan commented 2 hours ago

Just published a new version 0.1.3 fixing this types entry. Can you give it a try?