Skip to content

Commit fab15d3

Browse files
committed
Fix String.dedent type
1 parent cd858d3 commit fab15d3

File tree

4 files changed

+51
-10
lines changed

4 files changed

+51
-10
lines changed

packages/core-js-types/src/base/proposals/string-dedent.d.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,20 @@ interface StringConstructor {
44
/**
55
* Template tag that removes common leading whitespace from every line in the resulting string,
66
* preserving relative indentation and blank lines.
7-
* @param strings The template strings array.
7+
* @param template The template strings array, strings array, or a single string.
88
* @param values Values to be interpolated into the template string.
99
* @returns The dedented string.
1010
*/
11-
dedent(strings: TemplateStringsArray, ...values: any[]): string;
11+
dedent(template: TemplateStringsArray | ArrayLike<string>, ...values: any[]): string;
12+
dedent(template: { raw: readonly string[] }, ...values: any[]): string;
13+
dedent(template: string): string;
14+
}
15+
16+
interface String {
17+
/**
18+
* Template tag that removes common leading whitespace from every line in the resulting string,
19+
* preserving relative indentation and blank lines.
20+
* @returns The dedented string.
21+
*/
22+
dedent(): string;
1223
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/// <reference types="../../core-js-types/string-base.d.ts" />
2+
3+
// Motivation: We should use String without the matchAll method to avoid signature conflicts
4+
5+
// https://github.com/tc39/proposal-string-dedent
6+
7+
declare namespace CoreJS {
8+
export interface CoreJSStringConstructor extends StringConstructor {
9+
10+
/**
11+
* Template tag that removes common leading whitespace from every line in the resulting string,
12+
* preserving relative indentation and blank lines.
13+
* @param template The template strings array, strings array, or a single string.
14+
* @param values Values to be interpolated into the template string.
15+
* @returns The dedented string.
16+
*/
17+
dedent(template: TemplateStringsArray | ArrayLike<string>, ...values: any[]): string;
18+
dedent(template: { raw: readonly string[] }, ...values: any[]): string;
19+
dedent(template: string): string;
20+
}
21+
22+
var CoreJSString: CoreJSStringConstructor;
23+
24+
export interface CoreJSString extends StringBase {
25+
/**
26+
* Template tag that removes common leading whitespace from every line in the resulting string,
27+
* preserving relative indentation and blank lines.
28+
* @returns The dedented string.
29+
*/
30+
dedent(): string;
31+
}
32+
}

tests/type-definitions/global/proposals/string-dedent.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ const rdedent2: string = String.dedent`line1
88
const tpl = Object.assign(['foo', 'bar'], { raw: ['foo', 'bar'] }) as TemplateStringsArray;
99
String.dedent(tpl, 1, 2);
1010

11-
// @ts-expect-error
12-
String.dedent(['foo', 'bar'], 1, 2);
13-
// @ts-expect-error
14-
String.dedent('foo', 1, 2);
11+
String.dedent({ raw: ["a\n b\n", "\n c\n"] }, 1, 2);
12+
13+
'string\ndedent'.dedent();
14+
1515
// @ts-expect-error
1616
String.dedent();

tests/type-definitions/pure/proposals/string-dedent.test.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ const rdedent2: string = stringDedent`line1
88
const tpl = Object.assign(['foo', 'bar'], { raw: ['foo', 'bar'] }) as TemplateStringsArray;
99
stringDedent(tpl, 1, 2);
1010

11-
// @ts-expect-error
12-
stringDedent(['foo', 'bar'], 1, 2);
13-
// @ts-expect-error
14-
stringDedent('foo', 1, 2);
11+
stringDedent({ raw: ["a\n b\n", "\n c\n"] }, 1, 2);
12+
1513
// @ts-expect-error
1614
stringDedent();

0 commit comments

Comments
 (0)