Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/Refine Type Inference for Objects with toJSON() Extending Primitives #690

Merged
merged 2 commits into from
Oct 17, 2023

Commits on Sep 23, 2023

  1. Refine Type Inference for Objects with toJSON() Extending Primitives

    Ensure objects implementing `toJSON()`, but also extending primitive
    types, have their type inferred by `toJSON()` and not by the extended
    type. This refinement helps prevent incorrect type inference for
    specialized objects with enhanced serialization.
    
    Changes:
        - Updated type conditions in `source/jsonify.d.ts` by prioritizing
          `{toJSON(): infer J}` case before primitives.
        - Added corresponding test cases in `test-d/jsonify.ts`.
    
    Example:
    This fix resolves issues like the incorrect inference of
    `Jsonify<Temporal.PlainDate>`, where `Temporal` is sourced from
    `@js-temporal/polyfill` and where `PlainDate` is extending `Boolean`.
    
    ```typescript
    import { Temporal } from '@js-temporal/polyfill';
    // Incorrectly inferred as Boolean, but string is expected
    Jsonify<Temporal.PlainDate>
    ```
    nrako committed Sep 23, 2023
    Configuration menu
    Copy the full SHA
    445eb76 View commit details
    Browse the repository at this point in the history

Commits on Oct 17, 2023

  1. Configuration menu
    Copy the full SHA
    a96e9cf View commit details
    Browse the repository at this point in the history