Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable noUncheckedIndexedAccess #16189

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

krassowski
Copy link
Member

@krassowski krassowski commented Apr 18, 2024

References

A number of errors in the codebase such as #15103 (comment) could be prevented by enabling noUncheckedIndexedAccess.

Trying to evaluate the benefit/cost ratio in this PR.

Related to #16038

Code changes

TBD

User-facing changes

None

Backwards-incompatible changes

None

Copy link

Thanks for making a pull request to jupyterlab!
To try out this branch on binder, follow this link: Binder

@krassowski
Copy link
Member Author

There is a few annoyances here:

val: string
const [key, value] = val.split('=');

both key and valueare treated as string | undefined although key is in fact string.

We cannot use parts.length > 1 for a check, but need to do parts[0] !== undefined:

export function join(...parts: string[]): string {
    if (parts[0] === undefined) {
      throw Error('join requires at least one string part')
    }
    parts[0]
}

Changing typing to:

export function join(...parts: [string, ...string[]]): string {
    parts[0]
}

works but requires calling with first ad rest like:

// cannot do this: join(...url.split('/').map(encodeURIComponent));
const [first, ...rest] = url.split('/').map(encodeURIComponent);
join(first as string, ...rest);

again because it cannot infer that first will be always string

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant