Skip to content

Invalid Types.array() checking #13

@Louprenard

Description

@Louprenard

Description
Some type checker in KsNumber used in combination with KsArray :
Edit : it also occurs with KsBoolean and KsString.

  • When calling test1 with a = 3 then a = null, it behaves as expected (null is rejected but 3 is accepted)
  • When calling test1 with a = null then a = 3, it behaves as expected (null is rejected but 3 is accepted)
  • When calling test2 with [{ "a": 3 }] then [{ "a": null }], it behaves as expected (null is rejected but 3 is accepted)
  • When calling test2 with [{ "a": null }] then [{ "a": 3 }], it treats the second as still being null (0.a: { "msg": "Cannot be null", "code": 3 })

Note that it may trigger a whole refresh of the app if used with tsc-watch, thus resolving the issue but not in a good way.

Packages
[email protected]
[email protected]

Minimal reproduction

import { Types, Route } from 'koa-smart';

@Route.Route({
  routeBase: '',
})
export default class RouteIndex extends Route {
  @Route.Post({
    bodyType: Types.object().keys({
      a: Types.number().required(),
    }),
  })
  async test1(ctx) {
    console.log(this.body(ctx));
  }

  @Route.Post({
    bodyType: Types.array().type(Types.object().keys({
      a: Types.number().required(),
    })),
  })
  async test2(ctx) {
    console.log(this.body(ctx));
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions