hperrin / svelte-material-ui

Svelte Material UI Components
https://sveltematerialui.com/
Apache License 2.0
3.31k stars 285 forks source link

`@smui/common` - typescript errors when `noUncheckedIndexedAccess` compiler option is enabled #531

Closed DetachHead closed 1 year ago

DetachHead commented 1 year ago

Describe the bug

c:\project\node_modules\@smui\common\src\internal\useActions.ts:42:11
Error: Cannot invoke an object which is possibly 'undefined'. 
        actionReturns.push(
          action(node as HTMLElement & SVGElement, actionEntry[1])
        );

c:\project\node_modules\@smui\common\src\internal\useActions.ts:45:28
Error: Cannot invoke an object which is possibly 'undefined'.
      } else {
        actionReturns.push(action(node as HTMLElement & SVGElement));
      }

c:\project\node_modules\@smui\common\src\internal\exclude.ts:10:23
Error: Object is possibly 'undefined'.
    const name = names[i];
    const cashIndex = name.indexOf('$');
    if (

c:\project\node_modules\@smui\common\src\internal\exclude.ts:13:20
Error: Object is possibly 'undefined'.
      cashIndex !== -1 &&
      keys.indexOf(name.substring(0, cashIndex + 1)) !== -1
    ) {

c:\project\node_modules\@smui\common\src\internal\exclude.ts:17:22
Error: Argument of type 'string | undefined' is not assignable to parameter of type 'string'.
  Type 'undefined' is not assignable to type 'string'.
    }
    if (keys.indexOf(name) !== -1) {
      continue;

c:\project\node_modules\@smui\common\src\internal\exclude.ts:20:44
Error: Type 'undefined' cannot be used as an index type.
    }
    newObj[name as keyof Partial<T>] = obj[name];
  }

c:\project\node_modules\@smui\common\src\internal\forwardEventsBuilder.ts:75:17
Error: Object is possibly 'undefined'.
              ? ':' + newEventTypeParts[i]
              : newEventTypeParts[i]
                  .split('-')

c:\project\node_modules\@smui\common\src\internal\forwardEventsBuilder.ts:99:9
Error: Type 'string | undefined' is not assignable to type 'string'.
  Type 'undefined' is not assignable to type 'string'.
        const parts = eventType.split(oldModifierMatch ? ':' : '$');
        eventType = parts[0];
        const eventOptions: {

c:\project\node_modules\@smui\common\src\internal\forwardEventsBuilder.ts:157:11
Error: Object is possibly 'undefined'.
      // Listen to all the events added before mount.
      $on(events[i][0], events[i][1]);
    }

c:\project\node_modules\@smui\common\src\internal\forwardEventsBuilder.ts:157:25
Error: Object is possibly 'undefined'.
      // Listen to all the events added before mount.
      $on(events[i][0], events[i][1]);
    }

c:\project\node_modules\@smui\common\src\internal\forwardEventsBuilder.ts:164:11
Error: Cannot invoke an object which is possibly 'undefined'.
        for (let i = 0; i < destructors.length; i++) {
          destructors[i]();
        }

c:\project\node_modules\@smui\common\src\internal\prefixFilter.ts:10:9
Error: Object is possibly 'undefined'.
    const name = names[i];
    if (name.substring(0, prefix.length) === prefix) {
      newObj[name.substring(prefix.length)] = obj[name];

c:\project\node_modules\@smui\common\src\internal\prefixFilter.ts:11:14
Error: Object is possibly 'undefined'.
    if (name.substring(0, prefix.length) === prefix) {
      newObj[name.substring(prefix.length)] = obj[name];
    }

c:\project\node_modules\@smui\common\src\internal\prefixFilter.ts:11:51
Error: Type 'undefined' cannot be used as an index type.
    if (name.substring(0, prefix.length) === prefix) {
      newObj[name.substring(prefix.length)] = obj[name];
    }

To Reproduce

  1. enable noUncheckedIndexedAccess in tsconfig.json:
    {
        "compilerOptions": {
            "strict": true,
            "noUncheckedIndexedAccess": true,
            "skipLibCheck": false
        }
    }
  2. run svelte-check

Expected behavior no errors

DetachHead commented 1 year ago

after some investigating i noticed that this is caused by typesVersions in the @smui/common package incorrectly pointing to the source code. see #532