Open heguro opened 1 month ago
Since all properties in
Obj
are optional, it should be possible to assignundefined
toobj[key]
regardless of thestrictNullChecks
setting.
That would depend on the exactOptionalPropertyTypes
setting.
That would depend on the exactOptionalPropertyTypes setting.
I didn't know that. However, at least in TypeScript 5.6.2 and 5.7.0-dev.20240914, it seems that strictNullChecks=false and exactOptionalPropertyTypes=true cannot be used together.
Edit: Added reference to exactOptionalPropertyTypes in Expected behavior.
Edit 2: Added delete
workground, which can be used with exactOptionalPropertyTypes: true
.
🔎 Search Terms
strictNullChecks false assign never
🕗 Version & Regression Information
⏯ Playground Link
https://www.typescriptlang.org/play/?strictNullChecks=false&ts=5.6.2#code/C4TwDgpgBA8gRgKygXigbwFBSmATgezAEYB+ALigGdhcBLAOwHMBuLHAsAJnKpoZbZ5CAZh70ArgFs4EXK2xCwAFh4ARAIbAIrAL6sMAegNQAwusrQiFAIIAbW+0KzgtCJSgALdQDdowD9CU6pJ+4NAAFNR0TACUGADG+PTUUABmRChQ4fiIFPAIADRQANYQIBQARIpEFVAAPlBVHJwVMSgAfOhsOQgA2qUgALqZ4vQAJhCpDBBjzFBGUABq6ra0Y92I-WXDqBL2cwvLq2NQAO4B9Lx08cAAcuL2JgHxxe607qkrFhh6GIbGZgsUE4FAAChxnK53F5fFAxrRUqlZBB6MB2LRJLQXLDQJB3JE+Ex6lAJNJZHFEsk0alOJlsrlYIgigNKtVag0miJWh0utgelshiNxpNprN5sYAKK4Ai4M4XK60G73R7PV5Qd5pL4QAB0UAlAA9IDcZlBgPgoDIoN4VmsNn0BjsSQ9bAdJdL8LhdQajVoTmaLdBrcc5SiFUrnU8IC83h8tWxKSkg5l+Q7XUsbSdwrjoBqovxiaSZLg4mwFgB1D3FdQEUbrbAJtE9WmoHpQczoao8Wsi+gzIqKUQUbtTXtjX58xCcAWO4eitNHW0ThBTh2ZPYu8Xp4PnUN58MqqNqjWfWzfbCHDNQCC+S6nLEeKAAAwg+vUNxgYBcSRW4KcuFAAAqYSUBQNDiBAj5FP4+DiIwD4yDCtAenCCJIrglBsBMtgQFoUAptsuj6AsgLQMIYIQv+ULqvQ8S2OIEwWvg-jopi2LQOo4x4YgUZotm+J5kSDQaFoFJJCkqTCHSPR5EyJRlKyHA1MSnLKNyyCdJgS7TkKEwjjM84Zna2m7M6BnbvKe53BGqoxpqp4QD8zBAA
💻 Code
🙁 Actual behavior
In Case 2, when
strictNullChecks
is false:undefined
results in an error: "Type 'undefined' is not assignable to type 'never'.(TS2322)"null
always results in an error: "Type 'null' is not assignable to type 'never'.(TS2322)"The behavior is inconsistent across different combinations of property types.
🙂 Expected behavior
Since all properties in
Obj
are optional, it should be possible to assignundefined
toobj[key]
regardless of thestrictNullChecks
setting, unlessexactOptionalPropertyTypes
is true (which cannot be used withstrictNullChecks: false
).Additionally, when
strictNullChecks
is false, assigningnull
should be allowed for all cases.Additional information about the issue
No response