szmarczak / http2-wrapper

Use HTTP/2 the same way like HTTP/1
MIT License
239 stars 18 forks source link

Bug: incorrect type definitions in `createResolveProtocol` function #107

Open shellvon opened 4 months ago

shellvon commented 4 months ago

Currently, the default cache type in the codebase is QuickLRU<string, string>, as seen in the implementation at this line and this line. However, according to the type definitions specified in the TypeScript declarations file here, the expected type for the cache is Map<string, string>.

When attempting to use this library, TypeScript reports a type mismatch error, likely because the provided type (QuickLRU<string, string>) does not match the expected type (Map<string, string>).

report example:

image

Given the current implementation, the cache type here can be any object that implements the following interface:

interface Cache {
    has(k: string): boolean;
    get(k: string): string | undefined;
}

In other words, cache can be any object instance that has both has and get methods defined.