fastify / fastify-type-provider-json-schema-to-ts

A Type Provider for json-schema-to-ts
MIT License
35 stars 8 forks source link

refactor: update types #72

Closed climba03003 closed 8 months ago

climba03003 commented 8 months ago

Closes #70 Closes #71 Fixes #68

Checklist

climba03003 commented 8 months ago

It somehow working on my side. Keep all packages the latest always the key in TypeScript world.

climba03003 commented 8 months ago

Interesting, it error only when using tsc but not the runtime.

The problem is non-strict mode.

mcollina commented 8 months ago

The problem is non-strict mode.

Confirmed.

Even with this change, tsserver still complains on my machine.

climba03003 commented 8 months ago

Even with this change, tsserver still complains on my machine.

The same error? Maybe try it from fresh.

git clone https://github.com/fastify/fastify-type-provider-json-schema-to-ts.git
cd fastify-type-provider-json-schema-to-ts
git checkout update
npm install
npm run build
npm run typescript
mcollina commented 8 months ago

Screenshot 2024-01-09 at 17 48 07

mcollina commented 8 months ago

The compilation still fail without --strict as well.

jfet97 commented 8 months ago

The strictNullChecks flag seems to be enough: npx tsc --strictNullChecks --noEmit types/*.ts doesn't emit any error.

Probably the library you are using relies on having null and undefined as distinct types while checking some base case for some recursive computation.

If strictNullChecks is false, null and undefined are assignable to all types, therefore any extends check could change behaviour if the checked type is null or undefined.

jfet97 commented 8 months ago

The documentation of json-schema-to-ts says exactly that strict: true is required

Screenshot_2024-01-09-21-50-26-12_40deb401b9ffe8e1df2f1cc5ba480b12.jpg

Uzlopak commented 8 months ago

@jfet97 Good point. If that is so, we should document it also in this repo.