Skip to content

Commit

Permalink
fix: update to TypeScript 4.8 (#1453)
Browse files Browse the repository at this point in the history
* fix: update to TypeScript 4.8

* style: fix lint
  • Loading branch information
WikiRik committed Oct 12, 2022
1 parent 9baa584 commit 5ddfa61
Show file tree
Hide file tree
Showing 25 changed files with 83 additions and 80 deletions.
26 changes: 13 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
"source-map-support": "0.5.21",
"sqlite3": "5.0.11",
"ts-node": "10.9.1",
"typescript": "4.7.4",
"typescript": "4.8.4",
"uuid-validate": "0.0.3"
},
"peerDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import { ModelType } from '../../model/model/model';
import { ThroughOptions } from '../through/through-options';

export class BelongsToManyAssociation<
TCreationAttributes,
TModelAttributes,
TCreationAttributesThrough,
TModelAttributesThrough
TCreationAttributes extends {},
TModelAttributes extends {},
TCreationAttributesThrough extends {},
TModelAttributesThrough extends {}
> extends BaseAssociation<TCreationAttributes, TModelAttributes> {
constructor(
associatedClassGetter: ModelClassGetter<TCreationAttributes, TModelAttributes>,
Expand Down
5 changes: 4 additions & 1 deletion src/associations/belongs-to-many/belongs-to-many-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import { BelongsToManyOptions as OriginBelongsToManyOptions } from 'sequelize';
import { ModelClassGetter } from '../../model/shared/model-class-getter';
import { ThroughOptions } from '../through/through-options';

export type BelongsToManyOptions<TCreationAttributesThrough, TModelAttributesThrough> = {
export type BelongsToManyOptions<
TCreationAttributesThrough extends {},
TModelAttributesThrough extends {}
> = {
[K in keyof OriginBelongsToManyOptions]: K extends 'through'
?
| ModelClassGetter<TCreationAttributesThrough, TModelAttributesThrough>
Expand Down
24 changes: 12 additions & 12 deletions src/associations/belongs-to-many/belongs-to-many.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,30 @@ import { ModelClassGetter } from '../../model/shared/model-class-getter';
import { addAssociation } from '../shared/association-service';

export function BelongsToMany<
TCreationAttributes,
TModelAttributes,
TCreationAttributesThrough,
TModelAttributesThrough
TCreationAttributes extends {},
TModelAttributes extends {},
TCreationAttributesThrough extends {},
TModelAttributesThrough extends {}
>(
associatedClassGetter: ModelClassGetter<TCreationAttributes, TModelAttributes>,
through: ModelClassGetter<TCreationAttributesThrough, TModelAttributesThrough> | string,
foreignKey?: string,
otherKey?: string
): Function;
export function BelongsToMany<
TCreationAttributes,
TModelAttributes,
TCreationAttributesThrough,
TModelAttributesThrough
TCreationAttributes extends {},
TModelAttributes extends {},
TCreationAttributesThrough extends {},
TModelAttributesThrough extends {}
>(
associatedClassGetter: ModelClassGetter<TCreationAttributes, TModelAttributes>,
options: BelongsToManyOptions<TCreationAttributesThrough, TModelAttributesThrough>
): Function;
export function BelongsToMany<
TCreationAttributes,
TModelAttributes,
TCreationAttributesThrough,
TModelAttributesThrough
TCreationAttributes extends {},
TModelAttributes extends {},
TCreationAttributesThrough extends {},
TModelAttributesThrough extends {}
>(
associatedClassGetter: ModelClassGetter<TCreationAttributes, TModelAttributes>,
throughOrOptions:
Expand Down
8 changes: 4 additions & 4 deletions src/associations/belongs-to/belongs-to-association.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import { Association } from '../shared/association';
import { ModelType } from '../../model/model/model';
import { UnionAssociationOptions } from '../shared/union-association-options';

export class BelongsToAssociation<TCreationAttributes, TModelAttributes> extends BaseAssociation<
TCreationAttributes,
TModelAttributes
> {
export class BelongsToAssociation<
TCreationAttributes extends {},
TModelAttributes extends {}
> extends BaseAssociation<TCreationAttributes, TModelAttributes> {
constructor(
associatedClassGetter: ModelClassGetter<TCreationAttributes, TModelAttributes>,
protected options: BelongsToOptions
Expand Down
6 changes: 3 additions & 3 deletions src/associations/belongs-to/belongs-to.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ import { BelongsToAssociation } from './belongs-to-association';
import { ModelClassGetter } from '../../model/shared/model-class-getter';
import { addAssociation, getPreparedAssociationOptions } from '../shared/association-service';

export function BelongsTo<TCreationAttributes, TModelAttributes>(
export function BelongsTo<TCreationAttributes extends {}, TModelAttributes extends {}>(
associatedClassGetter: ModelClassGetter<TCreationAttributes, TModelAttributes>,
foreignKey?: string
): Function;

export function BelongsTo<TCreationAttributes, TModelAttributes>(
export function BelongsTo<TCreationAttributes extends {}, TModelAttributes extends {}>(
associatedClassGetter: ModelClassGetter<TCreationAttributes, TModelAttributes>,
options?: BelongsToOptions
): Function;

export function BelongsTo<TCreationAttributes, TModelAttributes>(
export function BelongsTo<TCreationAttributes extends {}, TModelAttributes extends {}>(
associatedClassGetter: ModelClassGetter<TCreationAttributes, TModelAttributes>,
optionsOrForeignKey?: string | BelongsToOptions
): Function {
Expand Down
2 changes: 1 addition & 1 deletion src/associations/foreign-key/foreign-key-meta.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ModelClassGetter } from '../../model/shared/model-class-getter';

export interface ForeignKeyMeta<TCreationAttributes, TModelAttributes> {
export interface ForeignKeyMeta<TCreationAttributes extends {}, TModelAttributes extends {}> {
relatedClassGetter: ModelClassGetter<TCreationAttributes, TModelAttributes>;
foreignKey: string;
}
12 changes: 6 additions & 6 deletions src/associations/foreign-key/foreign-key-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import { ModelType } from '../../model/model/model';
const FOREIGN_KEYS_KEY = 'sequelize:foreignKeys';

export function getForeignKeyOptions<
TCreationAttributes,
TModelAttributes,
TCreationAttributesThrough,
TModelAttributesThrough
TCreationAttributes extends {},
TModelAttributes extends {},
TCreationAttributesThrough extends {},
TModelAttributesThrough extends {}
>(
relatedClass: ModelType<TCreationAttributes, TModelAttributes>,
classWithForeignKey?: ModelType<TCreationAttributesThrough, TModelAttributesThrough>,
Expand Down Expand Up @@ -48,7 +48,7 @@ export function getForeignKeyOptions<
/**
* Adds foreign key meta data for specified class
*/
export function addForeignKey<TCreationAttributes, TModelAttributes>(
export function addForeignKey<TCreationAttributes extends {}, TModelAttributes extends {}>(
target: any,
relatedClassGetter: ModelClassGetter<TCreationAttributes, TModelAttributes>,
foreignKey: string
Expand All @@ -67,7 +67,7 @@ export function addForeignKey<TCreationAttributes, TModelAttributes>(
/**
* Returns foreign key meta data from specified class
*/
export function getForeignKeys<TCreationAttributes, TModelAttributes>(
export function getForeignKeys<TCreationAttributes extends {}, TModelAttributes extends {}>(
target: any
): ForeignKeyMeta<TCreationAttributes, TModelAttributes>[] | undefined {
const foreignKeys = Reflect.getMetadata(FOREIGN_KEYS_KEY, target);
Expand Down
2 changes: 1 addition & 1 deletion src/associations/foreign-key/foreign-key.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { addForeignKey } from './foreign-key-service';
import { ModelClassGetter } from '../../model/shared/model-class-getter';

export function ForeignKey<TCreationAttributes, TModelAttributes>(
export function ForeignKey<TCreationAttributes extends {}, TModelAttributes extends {}>(
relatedClassGetter: ModelClassGetter<TCreationAttributes, TModelAttributes>
): Function {
return (target: any, propertyName: string) => {
Expand Down
8 changes: 4 additions & 4 deletions src/associations/has/has-association.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import { Association } from '../shared/association';
import { UnionAssociationOptions } from '../shared/union-association-options';
import { ModelType } from '../../model/model/model';

export class HasAssociation<TCreationAttributes, TModelAttributes> extends BaseAssociation<
TCreationAttributes,
TModelAttributes
> {
export class HasAssociation<
TCreationAttributes extends {},
TModelAttributes extends {}
> extends BaseAssociation<TCreationAttributes, TModelAttributes> {
constructor(
associatedClassGetter: ModelClassGetter<TCreationAttributes, TModelAttributes>,
protected options: HasManyOptions | HasOneOptions,
Expand Down
6 changes: 3 additions & 3 deletions src/associations/has/has-many.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ import { ModelClassGetter } from '../../model/shared/model-class-getter';
import { addAssociation, getPreparedAssociationOptions } from '../shared/association-service';
import { Association } from '../shared/association';

export function HasMany<TCreationAttributes, TModelAttributes>(
export function HasMany<TCreationAttributes extends {}, TModelAttributes extends {}>(
associatedClassGetter: ModelClassGetter<TCreationAttributes, TModelAttributes>,
foreignKey?: string
): Function;

export function HasMany<TCreationAttributes, TModelAttributes>(
export function HasMany<TCreationAttributes extends {}, TModelAttributes extends {}>(
associatedClassGetter: ModelClassGetter<TCreationAttributes, TModelAttributes>,
options?: HasManyOptions
): Function;

export function HasMany<TCreationAttributes, TModelAttributes>(
export function HasMany<TCreationAttributes extends {}, TModelAttributes extends {}>(
associatedClassGetter: ModelClassGetter<TCreationAttributes, TModelAttributes>,
optionsOrForeignKey?: string | HasManyOptions
): Function {
Expand Down
6 changes: 3 additions & 3 deletions src/associations/has/has-one.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ import { ModelClassGetter } from '../../model/shared/model-class-getter';
import { addAssociation, getPreparedAssociationOptions } from '../shared/association-service';
import { Association } from '../shared/association';

export function HasOne<TCreationAttributes, TModelAttributes>(
export function HasOne<TCreationAttributes extends {}, TModelAttributes extends {}>(
associatedClassGetter: ModelClassGetter<TCreationAttributes, TModelAttributes>,
foreignKey?: string
): Function;

export function HasOne<TCreationAttributes, TModelAttributes>(
export function HasOne<TCreationAttributes extends {}, TModelAttributes extends {}>(
associatedClassGetter: ModelClassGetter<TCreationAttributes, TModelAttributes>,
options?: HasOneOptions
): Function;

export function HasOne<TCreationAttributes, TModelAttributes>(
export function HasOne<TCreationAttributes extends {}, TModelAttributes extends {}>(
associatedClassGetter: ModelClassGetter<TCreationAttributes, TModelAttributes>,
optionsOrForeignKey?: string | HasOneOptions
): Function {
Expand Down
14 changes: 7 additions & 7 deletions src/associations/shared/association-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function getPreparedAssociationOptions(
/**
* Stores association meta data for specified class
*/
export function addAssociation<TCreationAttributes, TModelAttributes>(
export function addAssociation<TCreationAttributes extends {}, TModelAttributes extends {}>(
target: any,
association: BaseAssociation<TCreationAttributes, TModelAttributes>
): void {
Expand All @@ -44,7 +44,7 @@ export function addAssociation<TCreationAttributes, TModelAttributes>(
/**
* Returns association meta data from specified class
*/
export function getAssociations<TCreationAttributes, TModelAttributes>(
export function getAssociations<TCreationAttributes extends {}, TModelAttributes extends {}>(
target: any
): BaseAssociation<TCreationAttributes, TModelAttributes>[] | undefined {
const associations = Reflect.getMetadata(ASSOCIATIONS_KEY, target);
Expand All @@ -53,17 +53,17 @@ export function getAssociations<TCreationAttributes, TModelAttributes>(
}
}

export function setAssociations<TCreationAttributes, TModelAttributes>(
export function setAssociations<TCreationAttributes extends {}, TModelAttributes extends {}>(
target: any,
associations: BaseAssociation<TCreationAttributes, TModelAttributes>[]
): void {
Reflect.defineMetadata(ASSOCIATIONS_KEY, associations, target);
}

export function getAssociationsByRelation<TCreationAttributes, TModelAttributes>(
target: any,
relatedClass: any
): BaseAssociation<TCreationAttributes, TModelAttributes>[] {
export function getAssociationsByRelation<
TCreationAttributes extends {},
TModelAttributes extends {}
>(target: any, relatedClass: any): BaseAssociation<TCreationAttributes, TModelAttributes>[] {
const associations = getAssociations<TCreationAttributes, TModelAttributes>(target);
return (associations || []).filter((association) => {
const _relatedClass = association.getAssociatedClass();
Expand Down
2 changes: 1 addition & 1 deletion src/associations/shared/base-association.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ModelClassGetter } from '../../model/shared/model-class-getter';
import { ModelType } from '../../model/model/model';
import { Sequelize } from '../../sequelize/sequelize/sequelize';

export abstract class BaseAssociation<TCreationAttributes, TModelAttributes> {
export abstract class BaseAssociation<TCreationAttributes extends {}, TModelAttributes extends {}> {
constructor(
private associatedClassGetter: ModelClassGetter<TCreationAttributes, TModelAttributes>,
protected options: UnionAssociationOptions
Expand Down
2 changes: 1 addition & 1 deletion src/associations/through/through-options.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ThroughOptions as OriginThroughOptions } from 'sequelize';
import { ModelClassGetter } from '../../model/shared/model-class-getter';

export type ThroughOptions<TCreationAttributes, TModelAttributes> = {
export type ThroughOptions<TCreationAttributes extends {}, TModelAttributes extends {}> = {
[K in keyof OriginThroughOptions]: K extends 'model'
? ModelClassGetter<TCreationAttributes, TModelAttributes> | string
: OriginThroughOptions[K];
Expand Down
2 changes: 1 addition & 1 deletion src/model/model/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { AssociationActionOptions } from './association/association-action-optio
import { AssociationCreateOptions } from './association/association-create-options';
import { Repository } from '../../sequelize/repository/repository';

export type ModelType<TCreationAttributes, TModelAttributes> = new (
export type ModelType<TCreationAttributes extends {}, TModelAttributes extends {}> = new (
values?: TCreationAttributes,
options?: any
) => Model<TModelAttributes, TCreationAttributes>;
Expand Down
2 changes: 1 addition & 1 deletion src/model/shared/model-class-getter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ModelType } from '../model/model';

export type ModelClassGetter<TCreationAttributes, TModelAttributes> = (
export type ModelClassGetter<TCreationAttributes extends {}, TModelAttributes extends {}> = (
returns?: void
) => ModelType<TCreationAttributes, TModelAttributes>;
4 changes: 2 additions & 2 deletions src/scopes/default-scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ export function DefaultScope(scopeGetter: DefaultScopeGetter): Function;
* Decorator for defining default Model scope
* @deprecated
*/
export function DefaultScope<TCreationAttributes, TModelAttributes>(
export function DefaultScope<TCreationAttributes extends {}, TModelAttributes extends {}>(
scope: ScopeFindOptions<TCreationAttributes, TModelAttributes>
): Function;

/**
* Decorator for defining default Model scope
*/
export function DefaultScope<TCreationAttributes, TModelAttributes>(
export function DefaultScope<TCreationAttributes extends {}, TModelAttributes extends {}>(
scopeOrSsopeGetter: ScopeFindOptions<TCreationAttributes, TModelAttributes> | DefaultScopeGetter
): Function {
return (target: any) => {
Expand Down
4 changes: 2 additions & 2 deletions src/scopes/scope-find-options.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { Association, FindOptions, IncludeOptions } from 'sequelize';
import { ModelClassGetter } from '../model/shared/model-class-getter';

export type ScopeIncludeOptions<TCreationAttributes, TModelAttributes> = {
export type ScopeIncludeOptions<TCreationAttributes extends {}, TModelAttributes extends {}> = {
[K in keyof IncludeOptions]: K extends 'model'
? ModelClassGetter<TCreationAttributes, TModelAttributes>
: K extends 'include'
? ScopeIncludeOptions<TCreationAttributes, TModelAttributes>
: IncludeOptions[K];
};

export type ScopeFindOptions<TCreationAttributes, TModelAttributes> = {
export type ScopeFindOptions<TCreationAttributes extends {}, TModelAttributes extends {}> = {
[K in keyof FindOptions]: K extends 'include'
?
| ModelClassGetter<TCreationAttributes, TModelAttributes>[]
Expand Down

0 comments on commit 5ddfa61

Please sign in to comment.