Skip to content

Commit

Permalink
fix new typescript errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Picalines committed Sep 5, 2023
1 parent 042df71 commit e237b49
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
20 changes: 10 additions & 10 deletions src/database/Entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ import { Guild, GuildManager, GuildMember, GuildMemberManager, User, UserManager

export type EntityType = "user" | "guild" | "member";

export type Entity<E extends EntityType>
= E extends "user" ? User
: E extends "guild" ? Guild
: E extends "member" ? GuildMember
: never;
export type Entity<E extends EntityType> = {
"user": User,
"guild": Guild,
"member": GuildMember,
}[E];

export type AnyEntity = Entity<EntityType>;

export type EntityManager<E extends EntityType>
= E extends "user" ? UserManager
: E extends "guild" ? GuildManager
: E extends "member" ? GuildMemberManager
: never;
export type EntityManager<E extends EntityType> = {
"user": UserManager,
"guild": GuildManager,
"member": GuildMemberManager,
}[E];

export function checkEntityType<E extends EntityType>(entity: Entity<any>, expectedType: E): entity is Entity<E> {
switch (expectedType) {
Expand Down
2 changes: 1 addition & 1 deletion src/database/json/Handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const createJsonDatabaseHandler = (options: JsonHandlerOptions): CreateDa
}

variables ??= {};
const selected = [];
const selected: Entity<E>[] = [];

const defaultSatate = {} as any;
await database.bot.importer.forEach('states', state => {
Expand Down
2 changes: 1 addition & 1 deletion src/database/selector/Operator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export interface QueryOperators<E extends EntityType, Vars extends SelectorVars>
readonly var: <T>(name: ExpressionVariable<Vars, T>['name']) => ExpressionVariable<Vars, T>;
}

export const QueryOperators = <QueryOperators<EntityType, any>>Object.freeze({
export const QueryOperators = Object.freeze(<QueryOperators<EntityType, any>>{
gt: (l, r) => new ComparisonExpression('gt' as any, l, r),
gte: (l, r) => new ComparisonExpression('gte' as any, l, r),
lt: (l, r) => new ComparisonExpression('lt' as any, l, r),
Expand Down
2 changes: 1 addition & 1 deletion src/database/selector/Selector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class Selector<E extends EntityType, Vars extends SelectorVars = {}> {
}
}

function checkExpression<E extends EntityType>(selector: Selector<E, any>, expression?: AnyExpression<EntityType, any>) {
function checkExpression<E extends EntityType>(selector: Selector<E, any>, expression?: AnyExpression<E, any>) {
expression ??= selector.expression;

if (expression instanceof ComparisonExpression) {
Expand Down
2 changes: 1 addition & 1 deletion src/database/state/accessFabrics/JsonModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { assert } from "../../../utils/index.js";
import { StateAccess } from "../State.js";
import { jsonAccess } from "./Json.js";

export const jsonModelAccess = <T>(modelConstructor: new () => T) => (access: StateAccess<string>) => {
export const jsonModelAccess = <T extends {}>(modelConstructor: new () => T) => (access: StateAccess<string>) => {
const jAccess = jsonAccess<T>(access);

return {
Expand Down

0 comments on commit e237b49

Please sign in to comment.