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

Support TypeScript 4.1 via Babel #9473

Merged
merged 5 commits into from
Oct 22, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/language-js/printer-estree.js
Original file line number Diff line number Diff line change
Expand Up @@ -2943,6 +2943,14 @@ function printPathNoParens(path, options, print, args) {
if (n.constraint) {
parts.push(" in ", path.call(print, "constraint"));
}
if (parent.nameType) {
parts.push(
" as ",
path.callParent((path) => {
return path.call(print, "nameType");
})
);
}
parts.push("]");
return concat(parts);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`key-remapping.ts format 1`] = `
====================================options=====================================
parsers: ["babel-ts"]
printWidth: 80
| printWidth
=====================================input======================================
type MappedTypeWithNewKeys<T> = {
[K in keyof T as NewKeyType]: T[K]
};

type RemoveKindField<T> = {
[K in keyof T as Exclude<K, "kind">]: T[K]
};

type PickByValueType<T, U> = {
[K in keyof T as T[K] extends U ? K : never]: T[K]
};

=====================================output=====================================
type MappedTypeWithNewKeys<T> = {
[K in keyof T as NewKeyType]: T[K];
};

type RemoveKindField<T> = {
[K in keyof T as Exclude<K, "kind">]: T[K];
};

type PickByValueType<T, U> = {
[K in keyof T as T[K] extends U ? K : never]: T[K];
};

================================================================================
`;
4 changes: 4 additions & 0 deletions tests/typescript/key-remapping-in-mapped-types/jsfmt.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
run_spec(__dirname, [
// typescript-estree does not yet support Key Remapping in Mapped Types
"babel-ts",
]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
run_spec(__dirname, [
// typescript-estree does not yet support Key Remapping in Mapped Types
"babel-ts",
]);
run_spec(__dirname, ["babel-ts", "typescript"], {errors: {typescript: true}});

Will this work?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

f78e13b 👍

11 changes: 11 additions & 0 deletions tests/typescript/key-remapping-in-mapped-types/key-remapping.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
type MappedTypeWithNewKeys<T> = {
[K in keyof T as NewKeyType]: T[K]
};

type RemoveKindField<T> = {
[K in keyof T as Exclude<K, "kind">]: T[K]
};

type PickByValueType<T, U> = {
[K in keyof T as T[K] extends U ? K : never]: T[K]
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`template-literal-types.ts format 1`] = `
====================================options=====================================
parsers: ["babel-ts"]
printWidth: 80
| printWidth
=====================================input======================================
let x: \`foo-\${infer bar}\`;
type HelloWorld = \`\${Hello}, \${World}\`
type SeussFish = \`\${Quantity | Color} fish\`;
declare function setAlignment(value: \`\${VerticalAlignment}-\${HorizontalAlignment}\`): void;
type PropEventSource<T> = {
on(eventName: \`\${string & keyof T}Changed\`, callback: () => void): void;
};
type PropEventSource<T> = {
on<K extends string & keyof T>
(eventName: \`\${K}Changed\`, callback: (newValue: T[K]) => void ): void;
};

=====================================output=====================================
let x: \`foo-\${infer bar}\`;
type HelloWorld = \`\${Hello}, \${World}\`;
type SeussFish = \`\${Quantity | Color} fish\`;
declare function setAlignment(
value: \`\${VerticalAlignment}-\${HorizontalAlignment}\`
): void;
type PropEventSource<T> = {
on(eventName: \`\${string & keyof T}Changed\`, callback: () => void): void;
};
type PropEventSource<T> = {
on<K extends string & keyof T>(
eventName: \`\${K}Changed\`,
callback: (newValue: T[K]) => void
): void;
};

================================================================================
`;
4 changes: 4 additions & 0 deletions tests/typescript/template-literal-types/jsfmt.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
run_spec(__dirname, [
// typescript-estree does not yet support Template Literal Types
"babel-ts",
]);
11 changes: 11 additions & 0 deletions tests/typescript/template-literal-types/template-literal-types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
let x: `foo-${infer bar}`;
type HelloWorld = `${Hello}, ${World}`
type SeussFish = `${Quantity | Color} fish`;
declare function setAlignment(value: `${VerticalAlignment}-${HorizontalAlignment}`): void;
type PropEventSource<T> = {
on(eventName: `${string & keyof T}Changed`, callback: () => void): void;
};
type PropEventSource<T> = {
on<K extends string & keyof T>
(eventName: `${K}Changed`, callback: (newValue: T[K]) => void ): void;
};