Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add missing flow utils#201

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
dominictobias wants to merge6 commits intojoarwilk:master
base:master
Choose a base branch
Loading
fromdominictobias:master
Open
Show file tree
Hide file tree
Changes from1 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
PrevPrevious commit
feat: replace $PropertyType and $ElementType with indexed access type
  • Loading branch information
@dominictobias
dominictobias committedOct 4, 2023
commitac7505db74a2e5ade4644899752be9ffd28a5d02
8 changes: 4 additions & 4 deletionsREADME.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,7 +19,7 @@ It's surprisingly robust and non-lossy as it stands right now, in big part thank
| | Type guards | `(a: X) => a is A` | `(a: X) => boolean` |
| ✅ | Type parameter bounds | `function f<A extends string>(a:A){}` | `function f<A: string>(a:A){}` |
| ✅ | keyof X | `keyof X` | `$Keys<X>` |
| ✅ | X[keyof X] | `X[keyof X]` | `$ElementType<X,$Keys<X>>` |
| ✅ | X[keyof X] | `X[keyof X]` | `X[$Keys<X>]` |
| ✅ | Partial | `Partial<X>` | `$Rest<X, {}>` |
| ✅ | Readonly | `Readonly<X>` | `$ReadOnly<X>` |
| ✅ | ReadonlyArray | `ReadonlyArray<X>` | `$ReadOnlyArray<X>` |
Expand All@@ -35,9 +35,9 @@ It's surprisingly robust and non-lossy as it stands right now, in big part thank
| | InstanceType | `InstanceType<X>` | |
| ✅ | Required | `Required<X>` | `Required<X>` |
| | ThisType | `ThisType<X>` | |
| ✅ | T['string'] | `T['string']` | `$PropertyType<T, k>` |
| ✅ | T[k] | `T[k]` | `$ElementType<T, k>` |
| ✅ | Mapped types | `{[K in keyof Obj]: Obj[K]}` | `$ObjMapi<Obj, <K>(K) =>$ElementType<Obj, K>>` |
| ✅ | T['string'] | `T['string']` | `T['string']` |
| ✅ | T[k] | `T[k]` | `T[k]` |
| ✅ | Mapped types | `{[K in keyof Obj]: Obj[K]}` | `$ObjMapi<Obj, <K>(K) => Obj[K]>` |
| | Conditional types | `A extends B ? C : D` | `any` |
| ✅ | typeof operator | `typeof foo` | `typeof foo` |
| ✅ | Tuple type | `[number, string]` | `[number, string]` |
Expand Down
21 changes: 9 additions & 12 deletionssrc/__tests__/__snapshots__/duplicated-names.spec.ts.snap
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,10 +13,9 @@ declare export var AuthMechanism: {
+MONGODB_CR: \\"MONGODB-CR\\",
...
};
export type AuthMechanismType1 = $ElementType<
typeof AuthMechanism,
$Keys<typeof AuthMechanism>
>;
export type AuthMechanismType1 = (typeof AuthMechanism)[$Keys<
Copy link
Author

Choose a reason for hiding this comment

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

Don't know what is adding parenthesis around(typeof AuthMechanism) but it's not breaking types 🤷‍♂️

typeof AuthMechanism
>];
"
`;

Expand All@@ -26,10 +25,9 @@ exports[`should handle variable & type having same name 1`] = `
+MONGODB_CR: \\"MONGODB-CR\\",
...
};
export type AuthMechanismType = $ElementType<
typeof AuthMechanism,
$Keys<typeof AuthMechanism>
>;
export type AuthMechanismType = (typeof AuthMechanism)[$Keys<
typeof AuthMechanism
>];
"
`;

Expand All@@ -38,10 +36,9 @@ exports[`should support generic type rename 1`] = `
+off: \\"off\\",
...
}>;
export type ProfilingLevelType = $ElementType<
typeof ProfilingLevel,
$Keys<typeof ProfilingLevel>
>;
export type ProfilingLevelType = (typeof ProfilingLevel)[$Keys<
typeof ProfilingLevel
>];
export type Callback<T = any> = (error?: Error, result?: T) => void;
declare export var callback: Callback<ProfilingLevelType>;
"
Expand Down
7 changes: 2 additions & 5 deletionssrc/__tests__/__snapshots__/mapped-types.spec.ts.snap
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,10 +15,7 @@ declare type MappedUnion = $ObjMapi<
{ [k: SourceUnion]: any },
<K>(K) => Ref<number>
>;
declare type MappedObj = $ObjMapi<
SourceObject,
<K>(K) => Ref<$ElementType<SourceObject, K>>
>;
declare type ConstantKey = $PropertyType<MappedObj, \\"a\\">;
declare type MappedObj = $ObjMapi<SourceObject, <K>(K) => Ref<SourceObject[K]>>;
declare type ConstantKey = MappedObj[\\"a\\"];
"
`;
11 changes: 1 addition & 10 deletionssrc/printers/node.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -531,16 +531,7 @@ export const printType = withEnv<any, [any], string>(
return "boolean";

case ts.SyntaxKind.IndexedAccessType: {
let fn = "$ElementType";
if (
ts.isLiteralTypeNode(type.indexType) &&
type.indexType.literal.kind === ts.SyntaxKind.StringLiteral
) {
fn = "$PropertyType";
}
return `${fn}<${printType(type.objectType)}, ${printType(
type.indexType,
)}>`;
return `${printType(type.objectType)}[${printType(type.indexType)}]`;
}

case ts.SyntaxKind.TypeOperator:
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp