Skip to content

Commit

Permalink
Replace ArrayElementType<T> with T[number]
Browse files Browse the repository at this point in the history
  • Loading branch information
yu256 committed Dec 3, 2023
1 parent f835f91 commit b4c3d3b
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 8 deletions.
3 changes: 1 addition & 2 deletions packages/frontend/src/components/VrcUser.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@
<script lang="ts" setup>
import VrcAvatar from '@/components/VrcAvatar.vue';
import { HitUsers } from '@/scripts/vrchat-api';
import { ArrayElementType } from '@/types/custom-utilities';
defineProps<{
user: ArrayElementType<HitUsers>;
user: HitUsers[number];
}>();
</script>

Expand Down
3 changes: 1 addition & 2 deletions packages/frontend/src/pages/vrchat-world.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ import { User, World, fetchVrcWithAuth, addToFavorites } from '@/scripts/vrchat-
import { definePageMetadata } from '@/scripts/page-metadata';
import MkSelect from '@/components/MkSelect.vue';
import MkButton from '@/components/MkButton.vue';
import { ArrayElementType } from '@/types/custom-utilities';
import { toast } from '@/os';
const props = defineProps<{
Expand All @@ -63,7 +62,7 @@ fetchVrcWithAuth('world', props.id).then(async wrld => {
if (wrld) author.value = await fetchVrcWithAuth('user', wrld.authorId);
});
const selectedOption = ref<ArrayElementType<typeof options>['value']>('created_at');
const selectedOption = ref<typeof options[number]['value']>('created_at');
let timeKey = 0;
const options = [
Expand Down
4 changes: 2 additions & 2 deletions packages/frontend/src/scripts/vrchat-api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { defaultStore } from '@/store';
import { alert as miAlert, select, toast } from '@/os';
import { ArrayElementType, SomeRequired } from '@/types/custom-utilities';
import { SomeRequired } from '@/types/custom-utilities';

type ApiResponse<T> = { Success: T } | { Error: string };

Expand Down Expand Up @@ -187,7 +187,7 @@ export type User = {
isFriend: boolean;
location: string;
travelingToLocation?: string;
status: ArrayElementType<typeof status>;
status: typeof status[number];
statusDescription?: string;
rank: string;
};
Expand Down
2 changes: 0 additions & 2 deletions packages/frontend/src/types/custom-utilities.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
export type CustomPartial<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;

export type ArrayElementType<T> = T extends readonly (infer U)[] ? U : never;

export type SomeRequired<T, K extends keyof T> = Omit<T, K> & Required<RequiredNotNull<Pick<T, K>>>;
export type RequiredNotNull<T> = {
[P in keyof T]: NonNullable<T[P]>;
Expand Down

0 comments on commit b4c3d3b

Please sign in to comment.