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

Runtime mismatch with Intersection & Extends #1183

Open
jonasi opened this issue Feb 21, 2025 · 0 comments
Open

Runtime mismatch with Intersection & Extends #1183

jonasi opened this issue Feb 21, 2025 · 0 comments

Comments

@jonasi
Copy link

jonasi commented Feb 21, 2025

Extend at runtime doesn't seem to match its inferred type (nor typescript).

Here's a simple example:

import { Type, type Static } from '@sinclair/typebox';

const T = Type.Intersect([
    Type.Object({
        str: Type.String(),
    }),
    Type.Object({
        num: Type.Number(),
    }),
]);

type T = Static<typeof T>;
type R1 = T extends T ? true : false;

const R2 = Type.Extends(T, T, Type.Literal(true), Type.Literal(false));
type R2 = Static<typeof R2>;

const assertTrue1: R1 = true; // passes
const assertTrue2: R2 = true; // passes
if (!R2.const) {
    throw new Error(`oh no ${ R2.const.toString() }`);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant