Skip to content

Commit 544a846

Browse files
authored
Split: Enable strictLiteralChecks option by default (#1124)
1 parent 7cc84e3 commit 544a846

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

source/get.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ ToPath<'foo[0].bar.baz'>
6464
//=> ['foo', '0', 'bar', 'baz']
6565
```
6666
*/
67-
type ToPath<S extends string> = Split<FixPathSquareBrackets<S>, '.'>;
67+
type ToPath<S extends string> = Split<FixPathSquareBrackets<S>, '.', {strictLiteralChecks: false}>;
6868

6969
/**
7070
Replaces square-bracketed dot notation with dots, for example, `foo[0].bar` -> `foo.0.bar`.

source/split.d.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ type SplitOptions = {
1212
/**
1313
When enabled, instantiations with non-literal string types (e.g., `string`, `Uppercase<string>`, `on${string}`) simply return back `string[]` without performing any splitting, as the exact structure cannot be statically determined.
1414
15-
Note: In the future, this option might be enabled by default, so if you currently rely on this being disabled, you should consider explicitly enabling it.
16-
17-
@default false
15+
@default true
1816
1917
@example
2018
```ts
@@ -35,7 +33,7 @@ type SplitOptions = {
3533
};
3634

3735
type DefaultSplitOptions = {
38-
strictLiteralChecks: false;
36+
strictLiteralChecks: true;
3937
};
4038

4139
/**

test-d/split.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ expectType<['a', 'b', 'c'] | ['a,b,c'] | ['x', 'y', 'z'] | ['x:y:z']>({} as Spli
3838
// -- strictLiteralChecks: false --
3939
// NOTE: The behaviour covered in the test below is not acurate because the `a.b.${string}` type might hold a value like `a.b.c.d`,
4040
// which, when split by `.`, would result in `['a', 'b', 'c', 'd']`, which wouldn't conform to the output type of `['a', 'b', string]`.
41-
expectType<['a', 'b', string]>(split('a.b.c.d' as `a.b.${string}`, '.'));
41+
expectType<['a', 'b', string]>({} as Split<`a.b.${string}`, '.', {strictLiteralChecks: false}>);
4242

4343
// -- strictLiteralChecks: true --
44-
expectType<string[]>({} as Split<string, '', {strictLiteralChecks: true}>);
45-
expectType<string[]>({} as Split<Uppercase<string>, '-', {strictLiteralChecks: true}>);
46-
expectType<string[]>({} as Split<`on${string}`, 'n', {strictLiteralChecks: true}>);
47-
expectType<string[]>({} as Split<'a,b,c', string, {strictLiteralChecks: true}>);
48-
expectType<string[]>({} as Split<'a,b,c', Lowercase<string>, {strictLiteralChecks: true}>);
44+
expectType<string[]>({} as Split<string, ''>);
45+
expectType<string[]>({} as Split<Uppercase<string>, '-'>);
46+
expectType<string[]>({} as Split<`on${string}`, 'n'>);
47+
expectType<string[]>({} as Split<'a,b,c', string>);
48+
expectType<string[]>({} as Split<'a,b,c', Lowercase<string>>);
4949
expectType<string[]>({} as Split<'a,b,c', `,${string}`, {strictLiteralChecks: true}>);
5050
expectType<string[]>({} as Split<`on${string}`, Lowercase<string>, {strictLiteralChecks: true}>);
5151

0 commit comments

Comments
 (0)