Describe the bug
Hello, I have a TS project using SMUI and I want to turn on the exactOptionalPropertyTypes tsconfig option. The trouble is, since SMUI distributes TS source files, those get checked by the TS compiler as well, so the extra check gets applied to them as well... and it fails.
I would like to stress that this is not a false positive - the extra check uncovers what is really a potential issue in @smui/common. See the following line:
Here the new CustomEvent infers its T type from the type of the detail property - which with the extra check is more strictly inferred as T | undefined - this is IMHO correct, because the property is marked as optional in the function signature...
To Reproduce
Steps to reproduce the behavior:
Use @smui/common in a project (install it from NPM)
Turn on exactOptionalPropertyTypes
Expected behavior
No error
Actual behavior
/home/user/project/node_modules/@smui/common/src/internal/dispatch.ts:15:9
Error: Type 'CustomEvent<T | undefined>' is not assignable to type 'CustomEvent<T>'.
Type 'T | undefined' is not assignable to type 'T'.
'T | undefined' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'unknown'.
Type 'undefined' is not assignable to type 'T'.
'undefined' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'unknown'.
}
const event: CustomEvent<T> = new CustomEvent(eventType, {
...eventInit,
/home/user/project/node_modules/@smui/common/src/internal/dispatch.ts:21:11
Error: Type 'CustomEvent<T | undefined>' is not assignable to type 'CustomEvent<T>'.
if (duplicateEventForMDC && eventType.startsWith('SMUI')) {
const duplicateEvent: CustomEvent<T> = new CustomEvent(
eventType.replace(/^SMUI/g, () => 'MDC'),
Desktop (please complete the following information):
but I think you would probably want to turn this option on in your tsconfig as well? And I don't really know if this fix captures the semantics of what you want to do...
Describe the bug Hello, I have a TS project using SMUI and I want to turn on the
exactOptionalPropertyTypes
tsconfig option. The trouble is, since SMUI distributes TS source files, those get checked by the TS compiler as well, so the extra check gets applied to them as well... and it fails.I would like to stress that this is not a false positive - the extra check uncovers what is really a potential issue in
@smui/common
. See the following line:https://github.com/hperrin/svelte-material-ui/blob/19ea8edba225a22fbfbeeb76030a0d0f9ee1f8e5/packages/common/src/internal/dispatch.ts#L15-L18
Here the
new CustomEvent
infers itsT
type from the type of thedetail
property - which with the extra check is more strictly inferred asT | undefined
- this is IMHO correct, because the property is marked as optional in the function signature...To Reproduce Steps to reproduce the behavior:
@smui/common
in a project (install it from NPM)exactOptionalPropertyTypes
Expected behavior No error
Actual behavior
Desktop (please complete the following information):