Add Resolve<T> utility type

This commit is contained in:
Alex Gleason
2023-06-13 22:12:42 -05:00
parent db070150d9
commit 60eaf01940
3 changed files with 13 additions and 2 deletions

View File

@ -7,6 +7,8 @@ import { unescapeHTML } from 'soapbox/utils/html';
import { customEmojiSchema } from './custom-emoji';
import { contentSchema, filteredArray, makeCustomEmojiMap } from './utils';
import type { Resolve } from 'soapbox/utils/types';
const avatarMissing = require('assets/images/avatar-missing.png');
const headerMissing = require('assets/images/header-missing.png');
@ -142,6 +144,6 @@ const accountSchema = baseAccountSchema.extend({
moved: baseAccountSchema.transform(transformAccount).nullable().catch(null),
}).transform(transformAccount);
type Account = z.infer<typeof accountSchema>;
type Account = Resolve<z.infer<typeof accountSchema>>;
export { accountSchema, type Account };

View File

@ -16,6 +16,8 @@ import { pollSchema } from './poll';
import { tagSchema } from './tag';
import { contentSchema, dateSchema, filteredArray, makeCustomEmojiMap } from './utils';
import type { Resolve } from 'soapbox/utils/types';
const statusPleromaSchema = z.object({
emoji_reactions: filteredArray(emojiReactionSchema),
event: eventSchema.nullish().catch(undefined),
@ -144,6 +146,6 @@ const statusSchema = baseStatusSchema.extend({
};
}).transform(transformStatus);
type Status = z.infer<typeof statusSchema>;
type Status = Resolve<z.infer<typeof statusSchema>>;
export { statusSchema, type Status };

View File

@ -0,0 +1,7 @@
/**
* Resolve a type into a flat POJO interface if it's been wrapped by generics.
* https://gleasonator.com/@alex/posts/AWfK4hyppMDCqrT2y8
*/
type Resolve<T> = Pick<T, keyof T>;
export type { Resolve };