不要怂,就是干,撸起袖子干!

Commit 365d7c35 by Pedro Augusto de Paula Barbosa Committed by Sushant

fix(typings): queryInterface.addIndex (#11844)

1 parent fbd19d98
...@@ -4,6 +4,7 @@ import { Promise } from './promise'; ...@@ -4,6 +4,7 @@ import { Promise } from './promise';
import QueryTypes = require('./query-types'); import QueryTypes = require('./query-types');
import { Sequelize, RetryOptions } from './sequelize'; import { Sequelize, RetryOptions } from './sequelize';
import { Transaction } from './transaction'; import { Transaction } from './transaction';
import { SetRequired } from './../type-helpers/set-required';
type BindOrReplacements = { [key: string]: unknown } | unknown[]; type BindOrReplacements = { [key: string]: unknown } | unknown[];
type FieldMap = { [key: string]: string }; type FieldMap = { [key: string]: string };
...@@ -403,7 +404,7 @@ export class QueryInterface { ...@@ -403,7 +404,7 @@ export class QueryInterface {
): Promise<void>; ): Promise<void>;
public addIndex( public addIndex(
tableName: string, tableName: string,
options: QueryInterfaceIndexOptions & { fields: string[] }, options: SetRequired<QueryInterfaceIndexOptions, 'fields'>,
rawTablename?: string rawTablename?: string
): Promise<void>; ): Promise<void>;
......
...@@ -145,6 +145,15 @@ queryInterface.addIndex('Person', ['firstname', 'lastname'], { ...@@ -145,6 +145,15 @@ queryInterface.addIndex('Person', ['firstname', 'lastname'], {
type: 'UNIQUE', type: 'UNIQUE',
}); });
queryInterface.addIndex('Foo', {
name: 'foo_a',
fields: [
{ name: 'foo_b', order: 'DESC' },
'foo_c',
{ name: 'foo_d', order: 'ASC', collate: 'foobar', length: 42 }
],
});
queryInterface.removeIndex('Person', 'SuperDuperIndex'); queryInterface.removeIndex('Person', 'SuperDuperIndex');
// or // or
......
/**
* Full credits to sindresorhus/type-fest
*
* https://github.com/sindresorhus/type-fest/blob/v0.8.1/source/set-required.d.ts
*
* Thank you!
*/
export type SetRequired<BaseType, Keys extends keyof BaseType = keyof BaseType> =
// Pick just the keys that are not required from the base type.
Pick<BaseType, Exclude<keyof BaseType, Keys>> &
// Pick the keys that should be required from the base type and make them required.
Required<Pick<BaseType, Keys>> extends
// If `InferredType` extends the previous, then for each key, use the inferred type key.
infer InferredType
? {[KeyType in keyof InferredType]: InferredType[KeyType]}
: never;
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!