Skip to content

Utility type to pick fields from model #340

Description

@rsslldnphy
export type Model<
	K extends Capitalize<keyof M & string>,
	Fields extends
		| keyof ModelType<M[Uncapitalize<K> & keyof M]>
		| undefined = undefined,
> = [Fields] extends [undefined]
	? ModelType<M[Uncapitalize<K> & keyof M]>
	: Pick<
			ModelType<M[Uncapitalize<K> & keyof M]>,
			Fields & keyof ModelType<M[Uncapitalize<K> & keyof M]>
		>;

Usage: Model<"Organisation", "id" | "name">

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions