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

refactor(setSpace): fix typing #141

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

refactor(setSpace): fix typing #141

wants to merge 1 commit into from

Conversation

louh
Copy link
Member

@louh louh commented Jan 22, 2025

Fixes TypeScript errors in setSpace().

The main issue is this: setSpace accepts a three-letter string, where every three-letter combination of be statically checked by TypeScript. However, when running a substring(), the return type is a string, rather than one of the known letters, and keeping the return value a string literal is better for type safety.

After extensive research(!!!) it seems like the solution is just to say .substring() as MyType, because inputs are already typechecked and we just need to tell TypeScript that after this point the only valid values for substring() are values we know about, don't worry about it.

Also removes a code path for a position value of k which is never used and does the same thing as h.

@louh louh requested a review from slifty January 22, 2025 20:53
@louh louh self-assigned this Jan 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant