featurehub-io / featurehub-javascript-sdk

Official FeatureHub Javascript, Typescript, React, SolidJS, Node SDKs
MIT License
6 stars 4 forks source link

Property 'getAttrs' in type 'BaseClientContext' is not assignable to the same property in base type 'ClientContext' #151

Closed matt-oplo closed 1 year ago

matt-oplo commented 1 year ago

Describe the bug Using the SDK in a Typescript project with strict type checking enabled, produces the following error:

node_modules/featurehub-javascript-client-sdk/dist/context_impl.d.ts:24:5 - error TS2416: Property 'getAttrs' in type 'BaseClientContext' is not assignable to the same property in base type 'ClientContext'.
  Type '(key: string) => string[] | undefined' is not assignable to type '(key: string) => string[]'.
    Type 'string[] | undefined' is not assignable to type 'string[]'.
      Type 'undefined' is not assignable to type 'string[]'.

24     getAttrs(key: string): Array<string> | undefined;
       ~~~~~~~~

This is because the return types in the BaseClientContext abstract class and the ClientContext interface are different.

BaseClientContext:

getAttrs(key: string): Array<string> | undefined;

ClientContext:

getAttrs(key: string): Array<string>;

Which area does this issue belong to?

To Reproduce Steps to reproduce the behavior:

  1. Create a new typescript project.
  2. Set "strict": true in tsconfig.json
  3. Create a file that imports FeatureHubConfig.
  4. Build (tsc)
  5. See error

Expected behavior Project builds without errors.

Versions

rvowles commented 1 year ago

Now that opened a can of worms 😁

rvowles commented 1 year ago

@matt-oplo there is an attached PR, not sure if you would like to pull it down and compile it (if you use npm run compile - it will build and link it, so you can npm link featurehub-javascript-client-sdk into your codebase and check)

matt-oplo commented 1 year ago

Thanks. I'll have a look at it.

matt-oplo commented 1 year ago

@rvowles I've pulled the PR, built it, and linked it to my project which now builds without error.

rvowles commented 1 year ago

done and released as 1.3.0 @matt-oplo

matt-oplo commented 1 year ago

Thanks for your work on this @rvowles