Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Inline PropertyType utility type #238

Merged
merged 2 commits into from
Mar 7, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Inline PropertyType utility type
  • Loading branch information
kevinbarabash committed Mar 7, 2021
commit d571df11bf74d68018f50e540e6967b6d17e4fe4
7 changes: 4 additions & 3 deletions src/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ const utilityTypes = {
// The behavior of $Rest only differs when exact object types are involved.
// And since TypeScript doesn't have exact object types using $Diff is okay.
$Rest: "$Diff",
$PropertyType: null,
$PropertyType: (typeAnnotation, typeParam) => {
return t.tsIndexedAccessType(typeAnnotation, typeParam);
},
$ElementType: null,
$Call: null,
};
Expand Down Expand Up @@ -509,8 +511,7 @@ const transform = {
if (
(state.options.inlineUtilityTypes &&
typeof utilityTypes[typeName.name] === "function") ||
// $Exact doesn't exist in utility-types so we always inline it.
typeName.name === "$Exact"
typeName.name === "$Exact" // $Exact doesn't exist in utility-types so we always inline it.
) {
const inline = utilityTypes[typeName.name];
path.replaceWith(inline(...typeParameters.params));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
type C = $PropertyType<A, B>;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"inlineUtilityTypes": true}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
type C = A[B];