-
Notifications
You must be signed in to change notification settings - Fork 735
Closed
Labels
Domain: Type CheckingRelated to type checking, grammar checkingRelated to type checking, grammar checking
Description
This code is kinda cursed and there are many ways for us to fix it, but it errors slightly differently in TS vs. Go so I figured I'd report it in case it's unexpected.
type T = { type: "a"; a?: { k1: "v1"; k2: "v2" } } | { type: "b" };
function f(args?: Partial<T>) {}
export function g() {
f({ a: { k2: "v2" } });
}In TS we get:
src/partial.ts:6:7 - error TS2741: Property 'k1' is missing in type '{ k2: "v2"; }' but required in type '{ k1: "v1"; k2: "v2"; }'.
6 f({ a: { k2: "v2" } });
~
src/partial.ts:1:29
1 type T = { type: "a"; a?: { k1: "v1"; k2: "v2" } } | { type: "b" };
~~
'k1' is declared here.In Go we get:
src/partial.ts:6:5 - error TS2345: Argument of type '{ a: { k2: "v2"; }; }' is not assignable to parameter of type 'Partial<T> | undefined'.
Types of property 'a' are incompatible.
Property 'k1' is missing in type '{ k2: "v2"; }' but required in type '{ k1: "v1"; k2: "v2"; }'.
6 f({ a: { k2: "v2" } });
~~~~~~~~~~~~~~~~~~~
src/partial.ts:1:29 - 'k1' is declared here.
1 type T = { type: "a"; a?: { k1: "v1"; k2: "v2" } } | { type: "b" };
~~We noticed because in the original source the object is spread across a few lines, and currently it has @ts-expect-error which would then need to move to a different line. Plus in the real case it's better replaced by a cast anyway (or DeepPartial). So feel free to ignore if not useful!
Metadata
Metadata
Assignees
Labels
Domain: Type CheckingRelated to type checking, grammar checkingRelated to type checking, grammar checking