ship-hold icon indicating copy to clipboard operation
ship-hold copied to clipboard

Property 'run' does not exist on type 'ConditionsBuilder<SelectBuilder> & SelectBuilder'

Open sebtrif opened this issue 4 years ago • 1 comments

sh: latest master pg: 12 ts: 3.8.3

Hi!

First off thank you for this library! It's been pretty easy to use and I really appreciate feeling close to the DB, removes a lot of the friction I've experienced in the past

I've been trying to use it with TS and after a bunch of investigation it seems something is wrong with what functions are made available after a where function and TS gets confused.

To be clear, the code works perfectly! It's only TS that is complaining about this.

Here is what I'm seeing:


// Accounts.ts
import sh from '../db'; // taken from the readme, nothing special here

const Accounts = sh.service({
  table: 'accounts',
  primaryKey: 'id'
});

export { Accounts };

// sandbox.ts
import { Accounts } from './Accounts';

const getFilteredAccounts = async (accountId: string, profileId: string) => {
  const [account] = await Accounts.select() // .run is available here!
    .where('id', '$accountId')
    .and('profile_id', '$profileId')
    .run({ accountId: accountId, profileId: profileId }); // <-- .run is not available, this breaks with:
// Property 'run' does not exist on type 'ConditionsBuilder<SelectBuilder> & SelectBuilder'

  return account;  
}

I have seen the same behaviour when using update with a .where clause so without too much investigation I believe the types get messed up there

Please let me know if this doesn't classify as a bug, I'd be happy to take this to stackoverflow instead! Similarly if you have any pointers as to how I could fix it and send a PR i'd be happy to help and contribute!

Thank you!

sebtrif avatar Apr 16 '20 00:04 sebtrif

Thanks for the feedback. It is probably a bug. where initiates a proxy on top of the regular select builder and run comes from a mixin added to the regular select builder too. Many things to make the typing a bit tricky :)

lorenzofox3 avatar Apr 16 '20 07:04 lorenzofox3