-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
The inferred type of 'createTestModel' references an inaccessible 'unique symbol' type. #15898
Comments
I've removed the stale label to give us a bit more time to get to this report. There's been quite some changes under the hood since 6.13.0 due to our initial TypeScript migration which probably caused this issue |
This is still a blocker for me. I have found the following workaround, which seems to work for me: export interface TestModel extends Model<InferAttributes<TestModel>, InferCreationAttributes<TestModel>> {
id: string;
}
export function createTestModel(): ModelStatic<TestModel> {
return class TestModel extends Model {} as any;
} |
Same problem with follow code: function SomeFn() {
class AnimalModel extends Model {}
return AnimalModel;
}
export type TAnimalStatic = ReturnType<typeof SomeFn>;
export type TAnimalInstance = InstanceType<TAnimalStatic>; Typescript throw error only when exporting at least one type. Sequelize version: 6.35.2 |
This bug will be fixed after removing follow code sequelize/packages/core/src/model-typescript.ts Lines 353 to 356 in 1f99151
|
That's code from v7, and the original issue is for an issue in v6 where we do not have a model-typescript.ts file |
Oops.. My bad, sorry... There is also a error in v7 with same code examples. Maybe I will create issue for that later For v6 I created a PR. I don't know why there was a comment "Do not export", but if we export |
I'm trying to replicate the issue in https://github.com/sequelize/sequelize-sscce, I tried against Sequelize 6.36 and 7.0.0-alpha.36, with TypeScript 5.0.3 and 5.3.3, but I can't manage to get the error Could you fork that repo and try to replicate the bug there? |
You need to add option Before fix (#16933) After fix For sequelize vesrion 7.0.0+ typescript throw error |
Issue Creation Checklist
Bug Description
I am in the process of upgrading from Sequelize 6.3.5 to 6.30.0 (and from TypeScript 4.1.3 to 5.0.3). In my code I use functions that return model classes. While these functions previously worked, TypeScript is now throwing the following error:
This only happens when the function (or a type derived from it) is exported. If it is exclusively used within the model, no error is raised.
It seems that Sequelize 6.13.0 is that last version where this works without an error.
Reproducible Example
What do you expect to happen?
I expect the type to be inferred automatically, as it was possible in the previous version.
Environment
Would you be willing to resolve this issue by submitting a Pull Request?
Indicate your interest in the resolution of this issue by adding the 👍 reaction. Comments such as "+1" will be removed.
The text was updated successfully, but these errors were encountered: