Skip to content
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

Will it support typescript? #2

Closed
devilyouwei opened this issue Mar 14, 2023 · 7 comments
Closed

Will it support typescript? #2

devilyouwei opened this issue Mar 14, 2023 · 7 comments

Comments

@devilyouwei
Copy link

I am using node.js with TypeScript. I got an issue that DataTypes.VECTOR does not exist even if using registerType(Sequelize). Also, I will use an ORM which can cause more issues when DataType is not supported.

@ankane
Copy link
Member

ankane commented Mar 14, 2023

Hi @devilyouwei, added code for generating declaration files in the typescript branch, but they don't appear to be needed for new TypeScript projects (npx tsc --init). What error are you seeing with TypeScript?

Also, I'm not sure how to reproduce the DataTypes.VECTOR issue. Can you paste the full error message, backtrace, and relevant code?

@devilyouwei
Copy link
Author

devilyouwei commented Mar 15, 2023

Hi @ankane, actually, I am using sequelize-typescript to create MVC models and my issue is about Dtype declaration. There was no runtime error to reproduce because I even didn't succeed to run my code.
TS kept showing that there was no 'VECTOR' in Sequelize DataType. I did try to customize a VECTOR DataType by following the official document and your code. And finally, I found I need to use JS to register the type and I gave up.

I find a more simple approach to use VECTOR, directly using the string type, as the following TS code (egg.js Model):

import { Table, Column, AutoIncrement, PrimaryKey, Model, DataType, Sequelize } from 'sequelize-typescript'
// import pgvector from 'pgvector/sequelize'
// pgvector.registerType(Sequelize)

@Table({ modelName: 'page' })
export class Page extends Model {
    @PrimaryKey
    @AutoIncrement
    @Column({
        type: DataType.INTEGER
    })
    id: number

    @Column({
        type: DataType.INTEGER
    })
    page: number

    @Column({
        type: DataType.INTEGER
    })
    resourceId: number

    @Column({
        type: 'VECTOR(1536)'
    })
    embedding: string

    @Column({
        type: DataType.TEXT
    })
    content: string
}

export default () => Page

Thank you @ankane

@ankane
Copy link
Member

ankane commented Mar 15, 2023

fwiw, @Column(DataType.VECTOR(1536)) seems to work if you call pgvector.registerType(Sequelize), but glad you found another approach that works.

@ankane ankane closed this as completed Mar 15, 2023
@seyfer
Copy link

seyfer commented Mar 30, 2023

@ankane when I do import pgvector from 'pgvector/pg';

to register a type to pg client

(async () => {
  await pgvector.registerType(pgClient);
})();

I have in my WebStorm IDE and error

TS7016: Could not find a declaration file for module 'pgvector/pg'. '.../node_modules/pgvector/pg/index.js' implicitly has an 'any' type.   Try `npm i --save-dev @types/pgvector` if it exists or add a new declaration (.d.ts) file containing `declare module 'pgvector/pg';`

but there is no @types/pgvector exist.

ankane added a commit that referenced this issue Mar 31, 2023
@ankane
Copy link
Member

ankane commented Mar 31, 2023

Just pushed 0.1.1, which includes types.

Note: moduleResolution must be set to node16/nodenext in tsconfig.json for TypeScript to find them.

@wlaurance
Copy link
Contributor

I'm trying this now and I don't believe the types are included in the actual package file.

image

I tried to fix it with local linking the package and I made this change to make it work better #3

@amine-mf
Copy link

amine-mf commented Aug 17, 2023

Just pushed 0.1.1, which includes types.

Note: moduleResolution must be set to node16/nodenext in tsconfig.json for TypeScript to find them.

It seems like more than one person struggle with the issue, and it is not always an (easy) option to just migrate to nodenext.
Out of 8 issues, 3 are related to this (#11 and #7)
@ankane Is there any other workarounds (Could not find any myself)? Is there any chance to support node module resolution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

5 participants