sequelize / sequelize/sequelize
TypeScript - Cannot access static members of model with .schema() call
Open
Nobody has claimed this yet.
typescript
- Dominant language
- TypeScript
- Stars
- 30.4k
- Forks
- 4.3k
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 68
Description
Issue Description
When you call .schema() method of model then call static member typescript says that member doesn't exist.
What are you doing?
class TestModelWithStaticMethod extends Model {
static someStaticFn() {
return 'hello!';
}
};
TestModelWithStaticMethod.init({ hello: { type: DataTypes.BOOLEAN, allowNull: false } }, { sequelize });
const testModelWithStaticMethod = TestModelWithStaticMethod.schema('some_schema');
testModelWithStaticMethod.someStaticFn();
What do you expect to happen?
Ability to use static members of model without warnings.
What is actually happening?
> tsc -b types/tsconfig.json && tsc -b types/test/tsconfig.json
types/test/model.ts:86:27 - error TS2339: Property 'someStaticFn' does not exist on type '(new () => TestModelWithStaticMethod) & typeof Model'.
86 testModelWithStaticMethod.someStaticFn();
Environment
- Sequelize version: 5.x and 6.x
- Node.js version: v13.2.0
- Operating System: macOS 10.15.3
- If TypeScript related: TypeScript version: 3.7.2
Issue Template Checklist
How does this problem relate to dialects?
- I think this problem happens regardless of the dialect.
- I think this problem happens only for the following dialect(s):
- I don't know, I was using PUT-YOUR-DIALECT-HERE, with connector library version XXX and database version XXX
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 don't know how to start, I would need guidance.
- No, I don't have the time, although I believe I could do it if I had the time...
- No, I don't have the time and I wouldn't even know how to start.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the failing example in types/test/model.ts and the TypeScript build commands shown in the error. Trace the type returned by Model.schema(), then update the typing so subclass static members remain available and confirm both listed TypeScript builds pass.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- nodejs, typescript
- Domain
- backend, databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100