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
This changed between versions typescript@4.4.0-dev.20210601 and typescript@4.4.0-dev.20210602
Of course, this will not be happen if --strictOptionalProperties=false.
⏯ Playground Link
Playground link with relevant code
At this moment which I filed this issue, typescript playground does not prepare to use 4.4.0-dev.20210602.
💻 Code
interfaceA{a?: number;}functionouter(input: A){inner({// typescript compiler with `--strictOptionalProperties=true` will say here is error as// > Type 'number | undefined' is not assignable to type 'number'.// > Type 'undefined' is not assignable to type 'number'.ts(2322)a: input.a,});}functioninner(input: A){}
🙁 Actual behavior
TypeScript compiler fail to compile the the above example with the reason I commented.
After I read #43947, I could not conclude the current behavior is expected design. So I filed this as a bug.
🙂 Expected behavior
I thinks this should be pass to compile.
Remarks
If we pass outer's input to inner directly like the following example, typescript compile success to compile.
strictOptionalProperties means, roughly, that an optional property must either exist with the specified type, or not exist at all. Allowing the assignment would mean you've possibly created an explicit property with the value undefined, which is counter to the purpose of the flag.
Bug Report
🔎 Search Terms
--strictOptionalProperties
, Strict optional properties🕗 Version & Regression Information
typescript@4.4.0-dev.20210602
.typescript@4.4.0-dev.20210601
andtypescript@4.4.0-dev.20210602
--strictOptionalProperties=false
.⏯ Playground Link
Playground link with relevant code
At this moment which I filed this issue, typescript playground does not prepare to use
4.4.0-dev.20210602
.💻 Code
🙁 Actual behavior
TypeScript compiler fail to compile the the above example with the reason I commented.
After I read #43947, I could not conclude the current behavior is expected design. So I filed this as a bug.
🙂 Expected behavior
I thinks this should be pass to compile.
Remarks
If we pass
outer
'sinput
toinner
directly like the following example, typescript compile success to compile.The text was updated successfully, but these errors were encountered: