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

StringSlice<S, Start, End> returns incorrect type when S is non-literal string #1035

Closed
ghaaj opened this issue Jan 13, 2025 · 0 comments · Fixed by #1036
Closed

StringSlice<S, Start, End> returns incorrect type when S is non-literal string #1035

ghaaj opened this issue Jan 13, 2025 · 0 comments · Fixed by #1036
Labels
bug Something isn't working

Comments

@ghaaj
Copy link
Contributor

ghaaj commented Jan 13, 2025

Bug description

import type {StringSlice} from 'type-fest';

type Slice = StringSlice<string, 0, 1>; // string[]

export type StringSlice<
S extends string,
Start extends number = 0,
End extends number = StringToArray<S>['length'],
> = string extends S
? string[]
: ArraySlice<StringToArray<S>, Start, End> extends infer R extends readonly string[]
? Join<R, ''>
: never;

Line 34 should be modified to replace string[] with string.

Repro

https://www.typescriptlang.org/play/?#code/JYWwDg9gTgLgBDAnmApnA3gZRlYA7Ac0wBtgBjFAXzgDMoIQ4ByJVAWhpQGcYmBuALAAoYazQlyaALxxsuQhIoAeHvIIAaOAAZNARgB8goQEgA9KbgA9APzCzF1fgJxgXOCgAeqMjBQATTTwIeEdCAG0AXWEgA

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant