-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed as not planned
Closed as not planned
Copy link
Labels
Design LimitationConstraints of the existing architecture prevent this from being fixedConstraints of the existing architecture prevent this from being fixed
Description
π Search Terms
"typebox no Typescript error"
π Version & Regression Information
- This is a crash
β― Playground Link
π» Code
import { Static, Type } from '@sinclair/typebox';
// NATIVE EXAMPLE --------------
type SmallNativeType = {
level1: {
level2: {
foo: string;
};
};
};
type BigNativeType = {
level1: {
level2: {
foo: string;
bar: string;
};
};
};
// Two deeply nested types give correct error
function nativeBar(param: SmallNativeType[]): BigNativeType[] {
return param;
}
// --------------
// TYPEBOX EXAMPLE --------------
type SmallTypeboxType = Static<typeof SmallTypeboxType>;
const SmallTypeboxType = Type.Object({
level1: Type.Array(Type.Object({
level2: Type.Array(Type.Object({
foo: Type.String(),
})),
})),
});
type BigTypeboxType = Static<typeof BigTypeboxType>;
const BigTypeboxType = Type.Object({
level1: Type.Array(Type.Object({
level2: Type.Array(Type.Object({
foo: Type.String(),
bar: Type.String(),
})),
})),
});
// function foo(param: SmallTypeboxType): BigTypeboxType {
// return param;
// }
// Currently this is incorrect. It supposed to have error as in "nativeBar" example
// If you uncomment "foo" above: This will give error (correct behavior)
// If you uncomment "foo" below: This will NOT give error (incorrect behavior)
function bar(param: SmallTypeboxType[]): BigTypeboxType[] {
return param;
}
// function foo(param: SmallTypeboxType): BigTypeboxType {
// return param;
// }
// ------------------π Actual behavior
No Typescript error generated on line 58 inside bar function.
π Expected behavior
There should be an TS error on line 58 inside bar function just like there is a similar error inside nativeBar function on line 24.
Additional information about the issue
I first reported this issue to TypeBox repo, but I was advised that this is actually a Typescript problem.
Link to Typebox issue: sinclairzx81/typebox#636
Metadata
Metadata
Assignees
Labels
Design LimitationConstraints of the existing architecture prevent this from being fixedConstraints of the existing architecture prevent this from being fixed