SierraSoftworks/Iridium

Can't compile simple insert with TypeScript 2.4.1

haswalt opened this issue · 7 comments

Iridium Version: 8.0.0-alpha.2
NodeJS Version: 8.1.3
TypeScript Version: 2.4.1

Result

TypeScript fails to compile

Expected Result

TypeScript compiles

Steps to reproduce

Code a simple open connection and then insert.

import * as Iridium from "iridium";

interface RunDocument {
  _id?: string
  token: string
}

@Iridium.Collection('runs')
class Run extends Iridium.Instance<RunDocument, Run> implements RunDocument {
  @Iridium.ObjectID
  public _id: string

  @Iridium.Property(String)
  public token: string
}

class Database extends Iridium.Core {
  Runs = new Iridium.Model<RunDocument, Run>(this, Run);
}

let db = new Database({
  host: 'localhost',
  port: 27017
});

db.connect()
  .then(() => db.Runs.insert({
    token: 'test'
  }))
  .then(run => console.log(run));

Trying to compile this causes:

error TS2345: Argument of type '{ token: string; }' is not assignable to parameter of type 'RunDocument[]'.
  Object literal may only specify known properties, and 'token' does not exist in type 'RunDocument[]'

Hi @haswalt,

Thanks for bringing this to my attention, and especially for testing out the v8.0.0-alpha, I'll quickly see if I can get a fix out and let you know once I have.

Regards,
Benjamin

Hi @haswalt,

I'm trying to reproduce the issue you've sent through and have put together a repro test case, however I'm not having any issues with it. You can view the test case here, however it is essentially a copy-paste of your example with some wrapping code for the test runner.

Am I missing something from your example perhaps?

Regards,
Benjamin

Hi @spartan563,

I can't see anything extra my side compared to your test, except maybe typings being problematic?

Thanks,
Harry

Also here is my tsconfig.json:

{
  "compilerOptions": {
    "target": "es6",
    "module": "commonjs",
    "moduleResolution": "node",
    "sourceMap": false,
    "outDir": "dist",
    "baseUrl": ".",
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "removeComments": true,
    "alwaysStrict": true,
    "noUnusedParameters": true
  },
  "include": [
    "src/**/*.ts"
  ],
  "exclude": [
    "node_modules"
  ]
}

Looking into it more I have found a similar issue in another piece of code that is unrelated to this. It appears that for some reason TypeScript isn't recognising the method overload and so uses the first definition when compiling.

For example from mocha:

reporter(name: string): Mocha;
/** Sets reporter constructor, defaults to mocha.reporters.Spec. */
reporter(reporter: (runner: Mocha.IRunner, options: any) => any): Mocha;

using the second signature results in:

error TS2554: Expected 1 arguments, but got 2.

So there is a good chance that this is related to my setup here rather than Iridium itself.

I honestly have no idea why but some combination of TypeScript settings, versions and typings have conspired to break this. Having removed some global stuff and cleaned up I can no longer replicate.

Sorry for wasting your time and thanks for the lib.

Hi @haswalt,

I'm glad you managed to come right with this, incredibly odd and not something I've seen before. If you manage to figure out exactly what caused it, I'd love to hear so that I can help anybody who encounters the same issue in future.

Regards,
Benjamin