tomasz-zablocki / redux-orm-types Goto Github PK
View Code? Open in Web Editor NEWDefinitelyTyped definitions for redux-orm
License: MIT License
DefinitelyTyped definitions for redux-orm
License: MIT License
Most of the types from helper.d.ts
can be replaced with a depencency on utility-types
Is it possible we can add stateSelector to ORMOpts? Even if it is of any type, this will stop the compiler from complaining.
Currently, when we add stateSelector while initializing a new ORM object, below is what the compiler complains.
Argument of type '{ stateSelector: (state: any) => any; }' is not assignable to parameter of type 'ORMOpts'.
To produce this, create an ORM instance on a Typescript project with a stateSelector as below.
const orm = new ORM({
stateSelector: state => state.orm
});
Hi @tomasz-zablocki ,
For @types/redux-orm version 0.13.6. How to use selectors with passing an argument. In the example listed at
https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/redux-orm/redux-orm-tests.ts . All the filtering of data seems to be done from the parameters which are a part of the state.
How do i create a selector by explicitly passing an argument to it ?
The selector that i am trying is posted here :
redux-orm/redux-orm#328
Thanks .
ModelType should only expose methods from sharedMethod array:
QuerySet.sharedMethods = [
'count',
'at',
'all',
'last',
'first',
'filter',
'exclude',
'orderBy',
'update',
'delete',
];
toRefArray and toModelArray are accessible thru QS only
Tomasz,
Forgive me if I got this wrong, but it appears as though the mirror of this repo under DefinitelyTyped is stale. I tried including it in my project via DefinitelyTyped and noticed that ModelFields is outdated and resulted in compile errors.
New variant....
export type ModelFields = M['__fields'];
Stale in
https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/redux-orm/Model.d.ts
Fixed in
https://github.com/tomasz-zablocki/redux-orm-types/blob/master/types/redux-orm/Model.d.ts
I spent a lot of time trying to fix it myself before realizing that you already had a fix in place. Learned a lot along the way. Writing declaration files is a tough business, thanks for all your hard work!
Hi Tomasz,
Can you please write a guide how to migrate from old typescript definitions?
I tried but it was not something simple.
See this issue here for a summary of what I am hitting: redux-orm/redux-orm#331
Basically PR #257 in the redux-orm repo introduced the idea of a stateSelector
as an option to the ORM constructor + additional breaking changes to the createSelector
api. These type definitions then fell behind.
It seems like a relatively simple fix, but I just downloaded this library today to play with it (the core concept is amazing), and so am not totally familiar with what the change would require.
providing values for fields representing many
relations should be optional
The fields of a model are not available to methods defined on that model.
For example, in the following snippet, reading the title
field from an instance method reports a TypeScript error:
interface BookFields {
title: string
}
class Book extends Model<typeof Book, BookFields> {
...
getTitle() {
// Property 'title' does not exist on type 'Book'. ts(2339)
return this.title;
}
}
Add benchmarks to gauge the change impact on tsc performance
Tried running the playground project and it works fine . However when i integrate the new syntax with reactjs typescript template with fields still get the "Maximum stack error". Can you please help me with running the playground code with the attached template react ? I am quite clueless as to what needs to be done to get this to working.
I have tried with changing tsconfig values with no luck. Thanks in advance.
Optimize mapped types, focus on:
Resources
Current playground diagnostics:
Metric | Value |
---|---|
Files | 66 |
Lines | 12574 |
Nodes | 38223 |
Identifiers | 13284 |
Symbols | 16197 |
Types | 13419 |
Memory used | 50178K |
I/O read | 0.04s |
I/O write | 0.00s |
Parse time | 0.46s |
Bind time | 0.18s |
Check time | 0.84s |
Emit time | 0.00s |
Total time | 1.47s |
The session
static property is missing from the Model class, which causes the following code to raise a TS error - Property 'session' does not exist on type 'typeof Node'
.
/**
* Clones the node.
*/
public clone(): Node {
const {id, ...attributes} = this.ref;
return this.getClass().session.Node.create({
...attributes,
});
}
The session
getter is implemented here:
https://github.com/redux-orm/redux-orm/blob/3efec435039a56476da6872f623972021bd94703/src/Model.js#L207
Hi,
first, thank you for fantastic job)
I'm using right now the old version of @types/redux-orm
.
Can you please add a few examples how to use latest version of it?
Dennis
ModelType
narrowing utility may be replaced by prepending static methods with :
<M>(this: new (...args: any[]) => M,)
Model.exists
signature is identical to QuerySet.exists
In library source Model.exists
accepts a lookup obj as argument
/**
* Returns a boolean indicating if an entity
* with the given props exists in the state.
*
* @param {*} props - a key-value that {@link Model} instances should have to be considered as existing.
* @return {Boolean} a boolean indicating if entity with `props` exists in the state
*/
static exists(lookupObj) {
if (typeof this.session === 'undefined') {
throw new Error([
`Tried to check if a ${this.modelName} model instance exists without a session. `,
'Create a session using `session = orm.session()` and call ',
`\`session["${this.modelName}"].exists\` instead.`,
].join(''));
}
return Boolean(
this._findDatabaseRows(lookupObj).length
);
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.