Skip to content

Commit 88bfa65

Browse files
committed
Fix String dedent
1 parent 3c78a2c commit 88bfa65

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
// https://github.com/tc39/proposal-string-dedent
22

3+
type CoreJSTemplateTag = (template: TemplateStringsArray, ...values: any[]) => any;
4+
35
interface StringConstructor {
46
/**
57
* Template tag that removes common leading whitespace from every line in the resulting string,
68
* preserving relative indentation and blank lines.
7-
* @param template The template strings array, a single string, and function.
9+
* @param template The template strings array or function.
810
* @param values Values to be interpolated into the template string.
911
* @returns The dedented string.
1012
*/
1113
dedent(template: { raw: readonly string[] }, ...values: any[]): string;
12-
dedent(template: string): string;
13-
dedent<R extends string | { raw: readonly string[] }>(
14-
fn: (template: { raw: readonly string[] }, ...values: any[]) => R
15-
): (template: { raw: readonly string[] }, ...values: any[]) => string;
14+
dedent<T extends CoreJSTemplateTag>(tag: T): T;
1615
}

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

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

11-
String.dedent({ raw: ["a\n b\n", "\n c\n"] }, 1, 2);
11+
String.dedent({ raw: ['a\n b\n', '\n c\n'] }, 1, 2);
1212

13-
String.dedent(() => 'template string');
13+
const myTag = (strings: { raw: readonly string[]}, ...values: (string | number)[]) => {
14+
return { strings, values } as const;
15+
};
16+
const myAndDedent = String.dedent(myTag);
17+
myAndDedent`line1
18+
line2
19+
line3`;
1420

1521
// @ts-expect-error
1622
'string\ndedent'.dedent();

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

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

11-
stringDedent({ raw: ["a\n b\n", "\n c\n"] }, 1, 2);
11+
stringDedent({ raw: ['a\n b\n', '\n c\n'] }, 1, 2);
1212

13-
stringDedent(() => 'template string');
13+
const myTag = (strings: { raw: readonly string[]}, ...values: (string | number)[]) => {
14+
return { strings, values } as const;
15+
};
16+
const myAndDedent = stringDedent(myTag);
17+
myAndDedent`line1
18+
line2
19+
line3`;
1420

1521
// @ts-expect-error
1622
stringDedent();

0 commit comments

Comments
 (0)