You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
interfaceData{foo: string;bar: string;}interfaceOptionalData{foo: string;bar?: string;}// Case 1: Error// > Property 'bar' is missing in type '{ baz?: string | undefined; foo: string; }' but required in type 'Data'.constvalue1: Data={foo: 'FOO',
...{baz: "Bar"},};// Case 2: No Error ???constvalue2: OptionalData={foo: 'Foo',
...{baz: "Bar"},};// Case 3: Error// > Type '{ foo: string; baz: string; }' is not assignable to type 'OptionalData'.// > Object literal may only specify known properties, and 'baz' does not exist in type 'OptionalData'.constvalue3: OptionalData={foo: 'Foo',baz: 'Bar',};
π Actual behavior
In all cases, bar is misspelled as baz
In cases 1 and 3, typos can be detected as errors.
However, in case 2, the compilation succeeds without any errors.
π Expected behavior
In all cases, typos can be detected as errors.
Additional information about the issue
I found this bug when I was writing the following code with exactOptionalPropertyTypes set to true.
return{
foo,
...(bar!==undefined ? { bar } : {}),};
The text was updated successfully, but these errors were encountered:
π Search Terms
"spread operator", "optional property"
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play?#code/JYOwLgpgTgZghgYwgAgCJzHZBvAUMg5GAe2IC5kBnMKUAcwG59CAjOKC62kR3AX1y5QkWIhQB5AA5hgxEHAA26TDmYES5KjXpNCyNlAD8nbTyYDcAekvIAwnEooAjBQCiUKMShWbAPmQACp6S0GAAnsgA5AaRyMCUyAC28ZT0cSDI4SFR2PpwAF7GWtx0yAA+yACuIAAmEDCgEDUMRKQmJS18sSyVYMhQEACOlcADNemZYdmRynCRAHS4CHLUyABuipUQLmgYWAC8qnoaFJEAYuLikQA0asjzD9hs+RQARABC7K98t3xMPnYHCgAEwUAByxGQ7k8UGQhnhSxWfQ2Ci2oOQUhkckUs2QhzwxzaUTOpBudwe8yeBTenyg31+-2sgMcyAAzG4PF4Af4ACpTFCRXInYo6PIvEVmZBdOIJEDEPoOVJ0eQsBQoMCQrICzGyeRKPYLbkYlgAKwgCD6CmAIkUSTgETkCgilBCCGAMAiAGs5QB3DKSYKhYAQSjXZBwWpRZ6xGrEEPIOV9CAAD3ifVAk2mOux+swhuWIFWKK27Ix0l1OL2eKOhGF51Jtz0z1OtLJf2YQA
π» Code
π Actual behavior
In all cases,
bar
is misspelled asbaz
In cases 1 and 3, typos can be detected as errors.
However, in case 2, the compilation succeeds without any errors.
π Expected behavior
In all cases, typos can be detected as errors.
Additional information about the issue
I found this bug when I was writing the following code with
exactOptionalPropertyTypes
set to true.The text was updated successfully, but these errors were encountered: