types / sequelize Goto Github PK
View Code? Open in Web Editor NEWThe typings for https://github.com/sequelize/sequelize
The typings for https://github.com/sequelize/sequelize
I began working on the typings for Sequelize 4.0 in a branch: https://github.com/felixfbecker/typed-sequelize/tree/v4
and wanted to get some feedback / discussion. Basically whats changing in Sequelize 4.0 is that there is no Instance
class, but only an abstract Model
class. find()
etc. are static methods, and instances are actual instances of Model
. Sequelize.define()
now returns a subclass of Model
, and it is actually possible to subclass Model
on your own - this will allow us to define models as classes and use decorators to attach metadata.
I removed the generic type arguments to Model
and Instance
, because static methods cannot reference them anyway. So the attributes passed to update()
etc. will now be Object
.
Another problem is that TypeScript currently does not allow static methods to return a polymorphic this
- that means find()
can only return Model
, and it will be necassary to cast the return:
const user = await User.find() as User;
Also all the files use exports.default
in addition to module.exports
, so we can get rid of the exports =
. That makes all the files a lot cleaner and allows us to work more with classes instead of interfaces. I also started to move code out of the huge index.d.ts to exactly mirror the sequelize project structure.
I think this is rather self explanatory, right now the only real way to do this with typings is to create a new scope for each include scenario, which is rather annoying.
Method signature change(key: string, dirty: boolean): void
is missing in typings.
Across some of my apps, I pass request-level data into the save
and update
methods which I then re-use within various hooks (see here).
That said, I can't see a way of passing data via SaveOptions
. In vanilla JavaScript it works fine, also in TypeScript - but still, the compiler sometimes complains about things like the following, plus constantly highlights it as an error:
// via `save()` after setting some properties on the entity
await user.save({ctx: ctx}) as User;
// via `update()`
await user.update({firstName: 'John'}, {
ctx: ctx,
fields: ['firstName', 'lastName']
}) as User;
In this example, I am trying to pass the ctx
argument.
Is there any way of allowing this in npm-sequelize
? I tried it via Declaration Merging
and creating a new SaveOptions
interface - but to no avail.
I thought, perhaps in a newer version of TypeScript, there's a way of allowing additional, undefined properties to be set on an object (without losing typing).
Currently, Model.count has this signature:
count(options?: CountOptions): Promise<number>;
However, if you pass group
options to the count call, the return is an array. For example, assuming a naive blog posts table with an author_id
column:
const count = await Post.count();
// returns number
const count = await Post.count({group: ['author_id'], attributes: ['author_id']});
// returns [{count: 1, author_id: 1}, {count: 10, author_id: 2}];
The workaround is to add as any
after the call to suppress warnings. Not sure what the proper fix is in the type definition itself, but happy to PR with guidance :)
Sequelize.where()
objects cannot be passed to the where
optionArgument of type '{ offset: number; limit: number; order: string | fn | col | literal | (string | fn | col | litera...' is not assignable to parameter of type 'FindOptions'.
Types of property 'include' are incompatible.
Type '{ association: BelongsTo; include: { association: BelongsToMany; attributes: string[]; where: { [...' is not assignable to type '(Model<any, any> | Association | IncludeOptions)[]'.
Type '{ association: BelongsTo; include: { association: BelongsToMany; attributes: string[]; where: { [...' is not assignable to type 'Model<any, any> | Association | IncludeOptions'.
Type '{ association: BelongsTo; include: { association: BelongsToMany; attributes: string[]; where: { [...' is not assignable to type 'IncludeOptions'.
Types of property 'where' are incompatible.
Type 'where' is not assignable to type 'WhereOptions'.
Index signature is missing in type 'where'.
WhereNested
is only supports passing $and
and $or
?!WhereOptions
has Object
at the end, which means we can basically put anything in itWhereLogic
is basically uselesswhere
I would like to refactor all the where
options to use a single type alias that includes all possible options.
run tsc
TS2503: Cannot find namespace 'ValidatorJS'
Using a simple order option like [['createdAt', 'DESC']]
does not work:
await User.find({
order: [['createdAt', 'DESC']]
});
results in
[ts] Argument of type '{ where: { [x: string]: any; [x: number]: undefined; userId: any; }; order: [string[]]; attribute...' is not assignable to parameter of type 'FindOptions'.
Types of property 'order' are incompatible.
Type '[string[]]' is not assignable to type 'string | fn | col | literal | [string | col | fn | literal, string] | [Model<any, any> | { model:...'.
Type '[string[]]' is not assignable to type '(string | fn | col | literal | [string | col | fn | literal, string] | [Model<any, any> | { model...'.
Types of property '[Symbol.iterator]' are incompatible.
Type '() => IterableIterator<string[]>' is not assignable to type '() => IterableIterator<string | fn | col | literal | [string | col | fn | literal, string] | [Mod...'.
Type 'IterableIterator<string[]>' is not assignable to type 'IterableIterator<string | fn | col | literal | [string | col | fn | literal, string] | [Model<any...'.
Type 'string[]' is not assignable to type 'string | fn | col | literal | [string | col | fn | literal, string] | [Model<any, any> | { model:...'.
Type 'string[]' is not assignable to type '[Model<any, any>, Model<any, any>, string, string]'.
Property '0' is missing in type 'string[]'.
Order
is defined as
export type OrderItem =
string | fn | col | literal |
[string | col | fn | literal, string] |
[Model<any, any> | { model: Model<any, any>, as: string }, string, string] |
[Model<any, any>, Model<any, any>, string, string];
export type Order = OrderItem | OrderItem[];
I'm not sure why it doesn't work, any idea?
If you look at the source code, belongsToMany actually returns an association object that represents the association. It is recommended to save this object to pass it to the include
option of the find methods.
This also applies to hasMany and belongsTo
I might create a PR later for this as I already fixed it locally.
The following options are available for all methods that touch the database:
logging
benchmark
BelongsToManyGetAssociationsMixinOptions
and possibly other associations mixins don't allow to pass in FindOptions
even though this works perfectly fine.
It appears the current typings (tested at 09b3a90) are missing the include: [{all: true}]
option on the Includable
type in FindOptions
for eager-loading all included associations (as described here).
I guess this could easily be fixed by e.g. adding all?: boolean;
to the IncludeOptions
interface. If that doesn't work for you due to problems with interface reuse, a new IncludeAllOptions
interface would be minimal as well.
Happy to provide a PR if you want one for what could be a one-line change 😄
transaction
is missing in QueryInterfaceOptions
, although it takes the transaction correctly.
Add { distinct: boolean }
Hi, when I run npm install --save-dev types/sequelize I get the following errors, would someone be able to assist?
npm WARN addRemoteGit Error: Command failed: git -c core.longpaths=true config -
-get remote.origin.url
npm WARN addRemoteGit
npm WARN addRemoteGit at ChildProcess.exithandler (child_process.js:198:12)
npm WARN addRemoteGit at emitTwo (events.js:106:13)
npm WARN addRemoteGit at ChildProcess.emit (events.js:191:7)
npm WARN addRemoteGit at maybeClose (internal/child_process.js:891:16)
npm WARN addRemoteGit at Socket.<anonymous> (internal/child_process.js:342:1
1)
npm WARN addRemoteGit at emitOne (events.js:96:13)
npm WARN addRemoteGit at Socket.emit (events.js:188:7)
npm WARN addRemoteGit at Pipe._handle.close [as _onclose] (net.js:497:12)
npm WARN addRemoteGit types/sequelize resetting remote C:\Users\AshfordP\AppDat
a\Roaming\npm-cache\_git-remotes\git-github-com-types-sequelize-git-16fbe1d4 bec
ause of error: { Error: Command failed: git -c core.longpaths=true config --get
remote.origin.url
npm WARN addRemoteGit
npm WARN addRemoteGit at ChildProcess.exithandler (child_process.js:198:12)
npm WARN addRemoteGit at emitTwo (events.js:106:13)
npm WARN addRemoteGit at ChildProcess.emit (events.js:191:7)
npm WARN addRemoteGit at maybeClose (internal/child_process.js:891:16)
npm WARN addRemoteGit at Socket.<anonymous> (internal/child_process.js:342:1
1)
npm WARN addRemoteGit at emitOne (events.js:96:13)
npm WARN addRemoteGit at Socket.emit (events.js:188:7)
npm WARN addRemoteGit at Pipe._handle.close [as _onclose] (net.js:497:12)
npm WARN addRemoteGit killed: false,
npm WARN addRemoteGit code: 1,
npm WARN addRemoteGit signal: null,
npm WARN addRemoteGit cmd: 'git -c core.longpaths=true config --get remote.ori
gin.url' }
npm ERR! git clone --template=C:\Users\AshfordP\AppData\Roaming\npm-cache\_git-r
emotes\_templates --mirror git://github.com/types/sequelize.git C:\Users\Ashford
P\AppData\Roaming\npm-cache\_git-remotes\git-github-com-types-sequelize-git-16fb
e1d4: Cloning into bare repository 'C:\Users\AshfordP\AppData\Roaming\npm-cache\
_git-remotes\git-github-com-types-sequelize-git-16fbe1d4'...
npm ERR! git clone --template=C:\Users\AshfordP\AppData\Roaming\npm-cache\_git-r
emotes\_templates --mirror git://github.com/types/sequelize.git C:\Users\Ashford
P\AppData\Roaming\npm-cache\_git-remotes\git-github-com-types-sequelize-git-16fb
e1d4: fatal: unable to connect to github.com:
npm ERR! git clone --template=C:\Users\AshfordP\AppData\Roaming\npm-cache\_git-r
emotes\_templates --mirror git://github.com/types/sequelize.git C:\Users\Ashford
P\AppData\Roaming\npm-cache\_git-remotes\git-github-com-types-sequelize-git-16fb
e1d4: github.com[0: 192.30.253.112]: errno=No error
npm ERR! git clone --template=C:\Users\AshfordP\AppData\Roaming\npm-cache\_git-r
emotes\_templates --mirror git://github.com/types/sequelize.git C:\Users\Ashford
P\AppData\Roaming\npm-cache\_git-remotes\git-github-com-types-sequelize-git-16fb
e1d4: github.com[1: 192.30.253.113]: errno=No error
npm WARN addRemoteGit Error: Command failed: git -c core.longpaths=true config -
-get remote.origin.url
npm WARN addRemoteGit
npm WARN addRemoteGit at ChildProcess.exithandler (child_process.js:198:12)
npm WARN addRemoteGit at emitTwo (events.js:106:13)
npm WARN addRemoteGit at ChildProcess.emit (events.js:191:7)
npm WARN addRemoteGit at maybeClose (internal/child_process.js:891:16)
npm WARN addRemoteGit at Process.ChildProcess._handle.onexit (internal/child
_process.js:226:5)
npm WARN addRemoteGit types/validator#83990944fcc53bcb4b05b347c3cdfcb7aa05b3c7
resetting remote C:\Users\AshfordP\AppData\Roaming\npm-cache\_git-remotes\git-gi
thub-com-types-validator-git-83990944fcc53bcb4b05b347c3cdfcb7aa05b3c7-df0aafd5 b
ecause of error: { Error: Command failed: git -c core.longpaths=true config --ge
t remote.origin.url
npm WARN addRemoteGit
npm WARN addRemoteGit at ChildProcess.exithandler (child_process.js:198:12)
npm WARN addRemoteGit at emitTwo (events.js:106:13)
npm WARN addRemoteGit at ChildProcess.emit (events.js:191:7)
npm WARN addRemoteGit at maybeClose (internal/child_process.js:891:16)
npm WARN addRemoteGit at Process.ChildProcess._handle.onexit (internal/child
_process.js:226:5)
npm WARN addRemoteGit killed: false,
npm WARN addRemoteGit code: 1,
npm WARN addRemoteGit signal: null,
npm WARN addRemoteGit cmd: 'git -c core.longpaths=true config --get remote.ori
gin.url' }
npm ERR! git clone --template=C:\Users\AshfordP\AppData\Roaming\npm-cache\_git-r
emotes\_templates --mirror git://github.com/types/validator.git C:\Users\Ashford
P\AppData\Roaming\npm-cache\_git-remotes\git-github-com-types-validator-git-8399
0944fcc53bcb4b05b347c3cdfcb7aa05b3c7-df0aafd5: Cloning into bare repository 'C:\
Users\AshfordP\AppData\Roaming\npm-cache\_git-remotes\git-github-com-types-valid
ator-git-83990944fcc53bcb4b05b347c3cdfcb7aa05b3c7-df0aafd5'...
npm ERR! git clone --template=C:\Users\AshfordP\AppData\Roaming\npm-cache\_git-r
emotes\_templates --mirror git://github.com/types/validator.git C:\Users\Ashford
P\AppData\Roaming\npm-cache\_git-remotes\git-github-com-types-validator-git-8399
0944fcc53bcb4b05b347c3cdfcb7aa05b3c7-df0aafd5: fatal: unable to connect to githu
b.com:
npm ERR! git clone --template=C:\Users\AshfordP\AppData\Roaming\npm-cache\_git-r
emotes\_templates --mirror git://github.com/types/validator.git C:\Users\Ashford
P\AppData\Roaming\npm-cache\_git-remotes\git-github-com-types-validator-git-8399
0944fcc53bcb4b05b347c3cdfcb7aa05b3c7-df0aafd5: github.com[0: 192.30.253.112]: er
rno=No error
npm ERR! git clone --template=C:\Users\AshfordP\AppData\Roaming\npm-cache\_git-r
emotes\_templates --mirror git://github.com/types/validator.git C:\Users\Ashford
P\AppData\Roaming\npm-cache\_git-remotes\git-github-com-types-validator-git-8399
0944fcc53bcb4b05b347c3cdfcb7aa05b3c7-df0aafd5: github.com[1: 192.30.253.113]: er
rno=No error
[email protected] C:\Users\AshfordP\Documents\Private\briard-api
`-- @types/[email protected] (git+https://github.com/types/sequelize.git#505b409d
c42199abf5f0df5a9d9e86010850909f)
`-- @types/[email protected] (git+https://github.com/types/validator.git#839909
44fcc53bcb4b05b347c3cdfcb7aa05b3c7)
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.0.0 (node_modules\ch
okidar\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@
1.1.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"}
)
I tried using this syntax earlier today from here and it wasn't working:
interface UserInstance extends Sequelize.Instance<UserInstance, UserAttributes>, UserAttributes {
// getRole...
setRole: Sequelize.BelongsToSetAssociationMixin<RoleInstance, RoleId>;
// createRole...
}
TypeScript (2.0.3 btw) complains that Generic type 'Instance<TAttributes>' requires 1 type argument(s).
Replacing it with Sequelize.Instance<UserAttributes>
seems to work.
Further, RoleId
isn't described in the documentation; what is that value from? I supplied the type keyword for what that field is in my RoleAttributes interface and it seems to have worked.
Apologies if this is all working as it should and I'm just missing something obvious!
Trying to get scopes working with these typing and running into a confusing type error. Here's a minimal example that seems to fail with the following versions:
[email protected]
[email protected]
types/sequelize#2d9120f
import { Model, DataTypes } from "sequelize";
import sequelize from "../database";
class Message extends Model {}
Message.init(
{
private: DataTypes.BOOLEAN
},
{
sequelize,
scopes: {
private: {
where: {
private: true
}
}
}
}
);
let PrivateMessages = Message.scope("private");
PrivateMessages.findAll({
where: {}
});
// The 'this' context of type 'typeof Model' is not assignable to method's 'this' of type '(new () => Model) & typeof Model'.
// Type 'typeof Model' is not assignable to type 'new () => Model'.
// Cannot assign an abstract constructor type to a non-abstract constructor type.
Similarly to #112, I would expect typeof Model
to be new () => Model
, so I'm not sure why this intersection type fails.
I think such an important typing should be under types/. Moving a repo is pretty painless with GitHub.
Not sure whether I'm missing something really obvious here, but my models don't type check if I refer to the model classes within their methods.
import { Model, DataTypes } from "sequelize";
import sequelize from "./lib/sequelize";
class Message extends Model {
id: number;
text: string;
createFromEvent(event: string) {
return Message.create({ text: event });
}
}
Message.init({ text: DataTypes.STRING }, { sequelize });
The call to Message.create
fails with the following error.
The 'this' context of type 'typeof Message' is not assignable to method's 'this' of type '(new () => Message) & typeof Model'
I'm suffering from the fact that I'm not well versed in TypeScript and this error message is not transparent to me.
(new () => Message)
seems to be the type signature that would describe a constructor/class that returns Message
type objects. In which case, that should be satisfied by the fact that this is the Message class.typeof Model
which would presumably be equivalent to (new () => Model)
. I would have imagined that this was also satisfied because the Message class inherits from the model class.I'm in the process of converting existing Sequelize code to TypeScript and so I expect that one of the abstractions already in place is tripping me up. Either way, it would be great to have a reference example of a typed model definition that includes these kind of methods.
Branch | Build failing 🚨 |
---|---|
Dependency | typescript |
Current Version | 2.4.0 |
Type | devDependency |
This version is covered by your current version range and after updating it in your project the build failed.
As typescript is “only” a devDependency of this project it might not break production or downstream projects, but “only” your build or test tools – preventing new deploys or publishes.
I recommend you give this issue a high priority. I’m sure you can resolve this 💪
For release notes, check out the release announcement
For new features, check out the What's new in TypeScript 2.4.
For breaking changes, check out the Breaking changes in TypeScript 2.4 page.
For the complete list of fixed issues, check out the fixed issues query for Typescript 2.4.
Download:
The new version differs by 141 commits.
8b2fe13
Update LKG.
14d95ed
Test:Block-scoped definition of Promise works
a8846bf
Skip block scope check with no error location
44f2336
Merge pull request #16633 from Microsoft/release-2.4_fixIncrementalParsing
4875a27
Add tests
15ef20d
Set the structureReused to be safemoudles when dynamic import change
6d33083
Add tests
11b9f6e
Wip-fix incremental parsing
2721fd4
In TypeScript code, never bind JSDoc normally, just set parent pointers (#16555) (#16561)
0968ed9
Revert string enum changes (#16569)
096f8cc
Update LKG
9241175
Allow running in strict mode (#16557)
f49b007
Update LKG
f1b0f59
Update version to 2.4.1
ed9cde9
Update LKG
There are 141 commits in total.
See the full diff
There is a collection of frequently asked questions and of course you may always ask my humans.
Your Greenkeeper Bot 🌴
Branch | Build failing 🚨 |
---|---|
Dependency | typescript |
Current Version | 2.5.3 |
Type | devDependency |
This version is covered by your current version range and after updating it in your project the build failed.
typescript is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.
For release notes, check out the release announcement
For new features, check out the What's new in TypeScript 2.6.
For breaking changes, check out the Breaking changes in TypeScript 2.6 page.
For API breaking changes, check out the API Breaking changes in TypeScript 2.6 page.
For the complete list of fixed issues, check out the issues fixed in TypeScript 2.6 RC and after TypeScript 2.6 RC.
Download:
Special thanks to all contributors to this release:
The new version differs by 1177 commits ahead by 1177, behind by 85.
477bdc7
Update LKG
6bc04a9
Use lowercased names for generated locale directories (#19581)
0f32f55
Make getCompletionEntryDetails and getCompletionEntrySymbol parameters non-optional (#19507) (#19592)
1359a93
Update LKG
a7e172b
Support multiple completions with the same name but different source module (#19455) (#19496)
c35e90e
Merge pull request #19484 from Microsoft/reloadScriptsWithoutProject
96c66a6
Add test case to verify reload works without open project
b16e6d4
Reload contents of file from disk irrespective of project presence and file already containing its own text
6489a75
Update LKG
1a1c672
Merge pull request #19445 from Microsoft/foundWhileSearchingNodeModules
4e56347
Set the files found during node_modules search correctly when reusing existing program structure
aaaa280
Add the test case that fails and reports error for files not in root directory in watch mode
3134111
Merge pull request #19434 from Microsoft/port-master-10-23
a362bbf
Fix lint error
02cc07c
For @types installing quickfix, only activate for implicit-any module (#19394) (#19429)
There are 250 commits in total.
See the full diff
There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot 🌴
The Sequelize constructors accepts an options argument, which can have a operatorsAliases
key, found in the table in the docs here: http://docs.sequelizejs.com/class/lib/sequelize.js~Sequelize.html#instance-constructor-constructor
This options should be supported in the Sequelize type definitions as well.
this.dataValues
causes squiggly lines in instance methods since there's no definition for it ("TS2339: Property 'dataValues' does not exist on type 'User'.") - perhaps it's missing?
For example:
import * as _ from 'lodash';
class User extends Model {
public id: string;
[...]
public toJSON() {
return _.omit(this.dataValues, ['passwordHash']);
}
}
FindAttributeOptions can also be of the following type:
[[sequelize.literal('"a"."b"'), 'alias']]
The command you need to run is
typings install --save [email protected]
and not
typings install --save sequelize@4
as README.md
suggests.
@louy It is very cumbersome having to create a branch, commit, push, open a PR, wait for Travis, merge, delete branch just for a single commit if I already run the tests locally. Could you remove the status checks requirement? We can still wait until the checks are green for PRs, it's just not required anymore.
beforeSync
/ afterSync
/ beforeBulkSync
/ afterBulkSync
With Typescript2, it's able to install type definitions by just adding @types/sequelize
to the devDependency, without typings.
So I tried to migrate to devDependency with @types
from typings
, But it seems like it already taken by others: https://www.npmjs.com/package/@types/sequelize
The repository says it's for sequelize 4, but almost everything was broken.. is that right definitions?
Why don't we have generic for the model attributes?
e.g.
interface TypedModelAttributes {
id: number;
optionalData?: object;
}
class TypedModel extends Model<TypedModelAttributes> {
...
}
// usage
TypedModel.build({ ... }) // will be type-checked by "TypedModelAttributes"
TypedModel.findOne({ where: { ... }) // will be type-checked by "keyof TypedModelAttributes"
...
It is more accurate and will bring a lot of conveniences than current <K extends keyof this>
way.
class Student extends Model {}
Student.init() // <-- not working.
#When I tried to make a method that wraps model methods and return with default es6 Promise interface (declared from lib.es6.d.ts), it returns incompatible type error:
[ts] Bluebird<Model> is not compatible with Promise<Model>
So I changed promise.d.ts file like this
import * as Bluebird from 'bluebird';
export const Promise: typeof Bluebird;
// export type Promise<T> = Bluebird<T>;
export default Promise;
then the error has gone.
Consider this issue :)
I wrote code that looks like this:
import {DataTypes, Model, Sequelize} from 'sequelize';
class SavedQuery extends Model {
id: number;
name: string;
description: string;
author: string;
mtime: Date;
}
const sequelize = new Sequelize(config.database, config.user, config.password, sqlConfig);
SavedQuery.init({
name: DataTypes.STRING,
description: DataTypes.STRING,
author: DataTypes.STRING,
mtime: DataTypes.DATE,
}, {sequelize});
This type checks fine using [email protected] and [email protected]. But when I run it I get this error:
SavedQuery.init({
^
TypeError: SavedQuery.init is not a function
Is there something I'm missing here? I'm going straight off the test cases.
Hi,
I was trying to use Sequelize define method instead of Model.init(), but I cannot find a proper way to use it. I was trying to do it this way:
import { DataTypes, Model, ModelAttributes, ModelAttributeColumnOptions } from 'sequelize';
import sequelize from '../sequelize';//connection
class MyModel extends Model {
id: string;
foo() {}
}
const type = sequelize.define<MyModel>('MyModel', <ModelAttributes>{
id: <ModelAttributeColumnOptions>{
type: DataTypes.UUIDV4,
primaryKey: true,
},
});
type.findById('id'); // this causes transpilation error
According to typings define method returns an instance of type TModel
not the TModel
type itself, so it's impossible this way to use any of the static methods defined in Model
class. Is it possible to use this method at all, or it's currently required to use only Model.init()
method?
Changing the typing to define<TModel>(...): typeof Model
would allow access to Model
static methods but at the same moment it would make impossible to access any of the MyModel
attributes. Probably the easiest way would be making this function to return typeof TModel
but it didn't seem to be possible with TypeScript. Is any workaround for this?
Best
findOrCreate should return (instance, created) instead of a Model or I'm missing something?
The successful result of the promise will be (instance, created) - Make sure to use .spread()
static findOrCreate(options: FindOrInitializeOptions): Promise<Model>;
So this makes it not possible to use arrays destructuring like let [user, isCreated] = await Models.User.findOrCreate(..)
Edit: Used wrong version of the definition file, needed 3.
When using the latest type definitions with Sequelize 4.17.0, I get the following error when compiling with tsc
:
node_modules/@types/sequelize/lib/query-types.d.ts(3,16): error TS2714: The expression of an export assignment must be an identifier or qualified name in an ambient context.
Perhaps I'm missing something in my local setup, but this appears to be an issue with the Sequelize type definitions.
I am running typescript 2.6.0-rc
on Linux, 4.13.8-1-ARCH #1 SMP PREEMPT x86_64 GNU/Linux
, if that matters.
Hi, your definition file seems completely broken. When I include it in my project without even using it I get all these errors:
typings/main/definitions/sequelize/index.d.ts(825,15): error TS7006: Parameter 'options' implicitly has an 'any' type.
typings/main/definitions/sequelize/index.d.ts(832,13): error TS7006: Parameter 'value' implicitly has an 'any' type.
typings/main/definitions/sequelize/index.d.ts(832,20): error TS7006: Parameter 'options' implicitly has an 'any' type.
typings/main/definitions/sequelize/index.d.ts(833,12): error TS7006: Parameter 'options' implicitly has an 'any' type.
typings/main/definitions/sequelize/index.d.ts(1037,19): error TS7006: Parameter 'date' implicitly has an 'any' type.
typings/main/definitions/sequelize/index.d.ts(1038,15): error TS7006: Parameter 'date' implicitly has an 'any' type.
typings/main/definitions/sequelize/index.d.ts(1088,11): error TS7006: Parameter 'hext' implicitly has an 'any' type.
typings/main/definitions/sequelize/index.d.ts(1209,15): error TS7006: Parameter 'type' implicitly has an 'any' type.
typings/main/definitions/sequelize/index.d.ts(1209,21): error TS7006: Parameter 'srid' implicitly has an 'any' type.
typings/main/definitions/sequelize/index.d.ts(1229,3): error TS7010: 'construcor', which lacks return-type annotation, implicitly has an 'any' return type.
typings/main/definitions/sequelize/index.d.ts(1229,14): error TS7006: Parameter 'type' implicitly has an 'any' type.
typings/main/definitions/sequelize/index.d.ts(1229,20): error TS7006: Parameter 'srid' implicitly has an 'any' type.
typings/main/definitions/sequelize/index.d.ts(1230,3): error TS7010: 'construcor', which lacks return-type annotation, implicitly has an 'any' return type.
typings/main/definitions/sequelize/index.d.ts(1343,34): error TS7006: Parameter 'options' implicitly has an 'any' type.
typings/main/definitions/sequelize/index.d.ts(1343,43): error TS7006: Parameter 'Model' implicitly has an 'any' type.
typings/main/definitions/sequelize/index.d.ts(1346,37): error TS7006: Parameter 'options' implicitly has an 'any' type.
typings/main/definitions/sequelize/index.d.ts(1346,46): error TS7006: Parameter 'Model' implicitly has an 'any' type.
typings/main/definitions/sequelize/index.d.ts(1348,36): error TS7006: Parameter 'attributes' implicitly has an 'any' type.
typings/main/definitions/sequelize/index.d.ts(1348,48): error TS7006: Parameter 'Model' implicitly has an 'any' type.
typings/main/definitions/sequelize/index.d.ts(1350,36): error TS7006: Parameter 'dataValues' implicitly has an 'any' type.
typings/main/definitions/sequelize/index.d.ts(1350,48): error TS7006: Parameter 'fields' implicitly has an 'any' type.
typings/main/definitions/sequelize/index.d.ts(1350,56): error TS7006: Parameter 'Model' implicitly has an 'any' type.
typings/main/definitions/sequelize/index.d.ts(1353,36): error TS7006: Parameter 'args' implicitly has an 'any' type.
typings/main/definitions/sequelize/index.d.ts(1353,42): error TS7006: Parameter 'primaryKeys' implicitly has an 'any' type.
typings/main/definitions/sequelize/index.d.ts(1373,39): error TS7006: Parameter 'hash' implicitly has an 'any' type.
typings/main/definitions/sequelize/index.d.ts(1373,45): error TS7006: Parameter 'omitNull' implicitly has an 'any' type.
typings/main/definitions/sequelize/index.d.ts(1373,55): error TS7006: Parameter 'options' implicitly has an 'any' type.
typings/main/definitions/sequelize/index.d.ts(1374,25): error TS7006: Parameter 'SubClass' implicitly has an 'any' type.
typings/main/definitions/sequelize/index.d.ts(1374,35): error TS7006: Parameter 'SuperClass' implicitly has an 'any' type.
typings/main/definitions/sequelize/index.d.ts(1376,27): error TS7006: Parameter 'args' implicitly has an 'any' type.
typings/main/definitions/sequelize/index.d.ts(1376,33): error TS7006: Parameter 'begin' implicitly has an 'any' type.
typings/main/definitions/sequelize/index.d.ts(1391,15): error TS7006: Parameter 'fn' implicitly has an 'any' type.
typings/main/definitions/sequelize/index.d.ts(1391,19): error TS7006: Parameter 'args' implicitly has an 'any' type.
typings/main/definitions/sequelize/index.d.ts(1397,15): error TS7006: Parameter 'col' implicitly has an 'any' type.
typings/main/definitions/sequelize/index.d.ts(1401,15): error TS7006: Parameter 'val' implicitly has an 'any' type.
typings/main/definitions/sequelize/index.d.ts(1405,15): error TS7006: Parameter 'val' implicitly has an 'any' type.
typings/main/definitions/sequelize/index.d.ts(1409,15): error TS7006: Parameter 'conditionsOrPath' implicitly has an 'any' type.
typings/main/definitions/sequelize/index.d.ts(1409,33): error TS7006: Parameter 'value' implicitly has an 'any' type.
typings/main/definitions/sequelize/index.d.ts(1413,15): error TS7006: Parameter 'attribute' implicitly has an 'any' type.
typings/main/definitions/sequelize/index.d.ts(1413,26): error TS7006: Parameter 'comparator' implicitly has an 'any' type.
typings/main/definitions/sequelize/index.d.ts(1413,38): error TS7006: Parameter 'logic' implicitly has an 'any' type.
typings/main/definitions/sequelize/index.d.ts(1418,34): error TS7006: Parameter 'obj' implicitly has an 'any' type.
Reported by @Thylossus in #14.
Changed type of return value of
Model<TInstance, TAttributes>.scope
fromthis
toModel<TInstance, TAttributes>
. The following example in https://github.com/Thylossus/sequelize-pull-request-justification-demo/tree/master tries to mimic the example from https://github.com/louy/typed-sequelize/blob/master/README.md.However, I cannot compile this example due to a type error:
index.ts(16,16): error TS2322: Type 'sequelize.Model<Thing, ThingInstance>' is not assignable to type 'sequelize.SequelizeStaticAndInstance.Model<Thing, ThingInstance>'. Types of property 'scope' are incompatible. Type '(options?: string | string[] | ScopeOptions | WhereOptions) => Model<Thing, ThingInstance>' is not assignable to type '(options?: string | string[] | ScopeOptions | WhereOptions) => this'. Type 'Model<Thing, ThingInstance>' is not assignable to type 'this'.
This is probably related to microsoft/TypeScript#5863. Changing the return type of scope solves the error for me.
Of course, this is not a sufficient criterion for changing your code, but I believe that isn't working for anyone. Feedback about the correctness of this assumption is very welcome.
Instead of receiveing IModelAttributes
(which forces the interface to declare all fields as optional) the method should receive a Partial<IModelAttributes>
I tried to update last night to the v4 typings and noticed I had to change my entire setup. Is there a reason that there is such a big difference between the v3 and v4 typings?
Would be better to make them more inline with each other, for upgrading purposes?
Is v4 is a better setup in the long run?
This makes it possible to install with npm to node_modules/@types
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.