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

The inferred type of 'createTestModel' references an inaccessible 'unique symbol' type. #15898

Open
3 of 6 tasks
cdauth opened this issue Apr 7, 2023 · 8 comments
Open
3 of 6 tasks
Labels
type: bug type: typescript For issues and PRs. Things that involve typescript, such as typings and intellisense.

Comments

@cdauth
Copy link

cdauth commented Apr 7, 2023

Issue Creation Checklist

  • I understand that my issue will be automatically closed if I don't fill in the requested information
  • I have read the contribution guidelines

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:

The inferred type of 'createTestModel' references an inaccessible 'unique symbol' type. A type annotation is necessary.ts(2527)

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

export function createTestModel() {
	return class TestModel extends Model {
		declare id: string;
	};
}

What do you expect to happen?

I expect the type to be inferred automatically, as it was possible in the previous version.

Environment

  • Sequelize version: 6.30.0
  • Node.js version: 19.7.0
  • TypeScript version: 5.0.3
  • Database & Version: (not relevant)
  • Connector library & Version: (not relevant)

Would you be willing to resolve this issue by submitting a Pull Request?

  • Yes, I have the time and I know how to start.
  • Yes, I have the time but I will need guidance.
  • No, I don't have the time, but my company or I are supporting Sequelize through donations on OpenCollective.
  • No, I don't have the time, and I understand that I will need to wait until someone from the community or maintainers is interested in resolving my issue.

Indicate your interest in the resolution of this issue by adding the 👍 reaction. Comments such as "+1" will be removed.

@cdauth cdauth added pending-approval Bug reports that have not been verified yet, or feature requests that have not been accepted yet type: bug labels Apr 7, 2023
@github-actions github-actions bot added the stale label Apr 22, 2023
@WikiRik WikiRik removed the stale label Apr 22, 2023
@WikiRik
Copy link
Member

WikiRik commented Apr 22, 2023

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

@github-actions github-actions bot added the stale label May 7, 2023
@WikiRik WikiRik removed the stale label May 7, 2023
@sequelize sequelize deleted a comment from github-actions bot May 21, 2023
@sequelize sequelize deleted a comment from github-actions bot May 21, 2023
@ephys ephys added type: typescript For issues and PRs. Things that involve typescript, such as typings and intellisense. and removed pending-approval Bug reports that have not been verified yet, or feature requests that have not been accepted yet labels May 21, 2023
@cdauth
Copy link
Author

cdauth commented Sep 12, 2023

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;
}

@ToTheHit
Copy link

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
Node.js version: 20.8.0
TypeScript version: 5.2.2

@ToTheHit
Copy link

ToTheHit commented Jan 3, 2024

This bug will be fixed after removing follow code

// TODO [>7]: Remove this
private static get _indexes(): never {
throw new Error('Model._indexes has been replaced with Model.getIndexes()');
}

@WikiRik
Copy link
Member

WikiRik commented Jan 3, 2024

This bug will be fixed after removing follow code

// TODO [>7]: Remove this
private static get _indexes(): never {
throw new Error('Model._indexes has been replaced with Model.getIndexes()');
}

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

@ToTheHit
Copy link

ToTheHit commented Jan 6, 2024

This bug will be fixed after removing follow code

// TODO [>7]: Remove this
private static get _indexes(): never {
throw new Error('Model._indexes has been replaced with Model.getIndexes()');
}

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 ForeignKeyBrand TypeScript's error will be fixed.

@ephys
Copy link
Member

ephys commented Feb 10, 2024

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?

@ToTheHit
Copy link

ToTheHit commented Feb 18, 2024

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 "declaration": true in tsconfig.json.

Before fix (#16933)

Screenshot before fix

image

After fix

Screenshot after fix

image

For sequelize vesrion 7.0.0+ typescript throw error TS4094: Property _indexes of exported class expression may not be private or protected.. In previous comment I suggested how to fix it.
BTW this is not a sequelize bug, but typescript:

  1. Allow .d.ts files to represent anonymous class expressions with private members microsoft/TypeScript#36060
  2. False error TS4094: ... exported class expression may not be private or protected. microsoft/TypeScript#30355

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug type: typescript For issues and PRs. Things that involve typescript, such as typings and intellisense.
Projects
None yet
Development

No branches or pull requests

4 participants