Skip to content

Commit

Permalink
Export InferFromColumn(s) types
Browse files Browse the repository at this point in the history
VSCode struggled to pick up on the type of Inferred models, so this change allows people to understand them better
  • Loading branch information
Skye-31 committed Oct 11, 2022
1 parent a3f08b8 commit 5d09207
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/smooth-colts-impress.md
@@ -0,0 +1,5 @@
---
"d1-orm": patch
---

Chore: export some types used by Model so VSC can pick up on them
10 changes: 8 additions & 2 deletions src/model.ts
Expand Up @@ -294,7 +294,10 @@ export enum DataTypes {
BOOLEAN = "boolean",
}

type InferFromColumn<T extends ModelColumn> =
/**
* This is a helper type that allows you to know the JS type of a {@link ModelColumn} type.
*/
export type InferFromColumn<T extends ModelColumn> =
T["type"] extends DataTypes.INTEGER
? number
: T["type"] extends DataTypes.REAL
Expand All @@ -307,7 +310,10 @@ type InferFromColumn<T extends ModelColumn> =
? 1 | 0
: never;

type InferFromColumns<T extends Record<string, ModelColumn>> = {
/**
* This is a helper type that allows you to know the JS type of a Record of {@link ModelColumn}s.
*/
export type InferFromColumns<T extends Record<string, ModelColumn>> = {
[K in keyof T]: InferFromColumn<T[K]>;
};

Expand Down

0 comments on commit 5d09207

Please sign in to comment.