Skip to content

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 is 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
@louh louh merged commit 2268bc4 into main Jan 27, 2025
1 check passed
@louh louh deleted the louh/set-space-ts branch January 27, 2025 01:20
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.

3 participants