-
-
Notifications
You must be signed in to change notification settings - Fork 529
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add TypeScript support #328
Comments
Really good proposition +1 |
The problem I see here is that the pattern I found to be the best for TypeScript is totally different than the approach sequelize-cli uses. The pattern of the exported closure and a static |
Does "Add TypeScript support" also include generating migrations? If so the only change there is to save the file as |
Well, putting just
|
What does this have to do with classes? |
Sorry, you are right. Thought about another thing. Another feature would be to have the classes above instead of the current syntax: |
You are thinking about models, not migration files. A migration file just exports two functions, up and down. |
+1 to this. Actually it should look not simply as file saved with .ts extension, but contain a slightly different contents in it, for example: import { QueryInterface } from 'sequelize';
import { DataType } from 'sequelize-typescript';
export async function up(query: QueryInterface) {
/*
Add altering commands here.
Example:
await query.createTable('users', { id: DataType.INTEGER });
console.log('Table users created!');
*/
}
export async function down(query: QueryInterface) {
/*
Add reverting commands here.
Example:
await query.dropTable('users');
console.log('Table users dropped!');
*/
} So:
Maybe it's even better to provide those possibilities in more generic way, like add an ability to provide user-defined template for those files. An I will be able to construct myself which dialect of javascript I use... |
@Mikhus YES! Native module support is required. The nice thing about your sample code is that you only introduce TypeScript to utilize QueryInterface. 👍 |
+1 |
3 similar comments
+1 |
+1 |
+1 |
thks @felixfbecker i'do that. |
@felixfbecker I have not used it in a project (but am planning to on mynext project), but have you seen the [sequelize-typescript)[https://github.com/RobinBuschmann/sequelize-typescript] project - it looks like a really interesting way of making Sequelize a bit more typescripty... I am not sure if that makes the generated application prescribe a package that people might not be familiar with / want. |
Another option would be to treat the This might look something like: Directory Structure
package.json {
"name": "create-observable-thunk",
"main": "./index.js",
"typings": "./index.d.ts",
} types.d.ts import * as Sequelize from "sequelize"
export const Sequelize: Sequelize
export const sequelize: Sequelize.Sequelize
export default namespace db {
} user.d.ts import * as Sequelize from "sequelize"
interface Attributes {
// ...
}
export default namespace db {
Cat: Sequelize.Model
} Note I haven't made sure these typings made sense. |
Until sequelize-cli has a TypeScript support option, the people on this thread may want to check out https://github.com/douglas-treadwell/sequelize-cli-typescript. (Note that it is already available on NPM.). I forked sequelize-cli and made a version that outputs TypeScripts (including migrations). See the README section "Differences...", but otherwise it works like regular sequelize-cli and should be a drop-in replacement. Also, by looking at the changes in my fork the maintainers of sequelize-cli or other contributors may be able to notice what sort of changes would be needed to support TypeScript in the mainline project. |
checkout this package which may help you to make typescript models and ease out models initialization |
I would request that instead of If coupled with registering transformations based on extension, we could support output in coffeescript, livescript, es6, etc |
append solution URL path consistently
Any updates on this? |
I assume the opinion has changed here since Sequelize 5 exports TypeScript types and could be of some value here. Would love type hints when writing my migrations as it's currently trial and error as the documentation often just says: "object" for options |
It seems that there has been no progress on this requirement, so does anyone knows a reliable way to perform migrations with TS? |
would like to know too |
Any news? This seems like a very good proposition. |
I'd better opt to migrate to Typeorm, since this library looks like this library is continuously ignoring Typescript support. |
@virgenherrera It doesn't make any sense to ignore it (if they seriously are). To work with databases and not to use TypeScript (which enforces types) seems rather ridiculous IMO. |
We're hard at work at improving TypeScript support for the main repo and we'll work on CLI after we've done most of our planned changes. v7 will have much better TypeScript support but we're open to PRs of the community in the meantime |
Since coffeescript is supported, i think it would be cool to have a typescript support also.
Expectation:
run node_modules/sequelize-cli/bin/sequelize model:create --name Collection --attributes id:integer,name:string --typescript
Will produce a model which ends in '.ts' instead of '.js'.
Justification:
In projects where typescript is used, javascript files are sometimes ignored (because they are produced through typescript). Therefore, the model will be ignored by default. Afterwards, a developer must edit the model/migration.
Result:
Tiny bit of work removed when developing with typescript.
The text was updated successfully, but these errors were encountered: