Skip to content
This repository has been archived by the owner on Dec 12, 2021. It is now read-only.

Typings improvments #258

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Typings improvments #258

wants to merge 3 commits into from

Conversation

aleek
Copy link

@aleek aleek commented Mar 13, 2018

I added ConstraintTypes and Contraints definition. Nice to have, also I like the intellisense in VSC.

  1. Tslint ran and all bugs fixed
  2. unit tests run, 0 bugs.

Please review. If you like that, I'll add TypeScript Unit tests to jasmine.
Treat this as Work In Progress - please don't merge yet.

@coveralls
Copy link

coveralls commented Mar 13, 2018

Coverage Status

Coverage remained the same at 100.0% when pulling d5a34a6 on aleek:typings into cccc345 on ansman:master.

@ElianCordoba
Copy link

Any updates on this?

@aleek
Copy link
Author

aleek commented May 8, 2018

@ElianCordoba what updates you'd like to see?

@ElianCordoba
Copy link

I just wanted to know the state of this PR, because i was thinking on doing it

@aleek
Copy link
Author

aleek commented May 14, 2018

Development is IMO currently done. Depends if someone thinks, I can improve something. Feel free to dev if you'd like.

@fugufish
Copy link

@aleek validate.options= for setting the default options is missing as well, I was going to add a PR but it seems more appropriate that it go here.

@drew-r
Copy link

drew-r commented Nov 29, 2018

I've had success with a mapped type for constraints.
e.g
validate<T>(attributes: T, constraints: Partial<{ [P in keyof T]: any }>)

@zepatrik
Copy link

Seems like @ansman won't merge it?

@grbspltt
Copy link

any chance of getting this PR merged?

(attributes: any, constraints: Constraints, options?: ValidateOption): any;
validate(attributes: any, constraints: Constraints, options?: ValidateOption): any;
async(attributes: any, constraints: Constraints, options?: AsyncValidateOption): Promise<any>;
single(value: any, constraints: Constraints, options?: ValidateOption): any;
Copy link

@stramel stramel May 7, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't constraints on single be of type ConstraintsTypes since it doesn't map to a key/name?

}

export interface Constraints {
[name: string]: ConstraintsTypes;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: Could we make use of Record here? export type Constraints = Record<string, ConstraintsTypes>

formatters: any;

(attributes: any, constraints: Constraints, options?: ValidateOption): any;
validate(attributes: any, constraints: Constraints, options?: ValidateOption): any;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you improve the return types on these? Maybe something like,
validate - Record<string, string[]> | undefined>
single - string[] | undefined
?

@ansman ansman force-pushed the master branch 4 times, most recently from feffe94 to 40e06a1 Compare June 15, 2019 17:55
@sarangjo
Copy link

Any chance that this can be merged in? The any types are really frustrating to work with.

@zepatrik
Copy link

What about adding either this typing or #302's to @DefinitelyTyped ? Who would be up for a PR there @sarangjo @aleek @mauricedoepke ? I could do it but not now...

@sarangjo
Copy link

Will that override the typings provided by this repo?

@zepatrik
Copy link

Hm right, good point. After a quick search I would guess one could do a combination of microsoft/TypeScript#25495 and https://stackoverflow.com/questions/40322788/how-to-overwrite-incorrect-typescript-type-definition-installed-via-types-packa
Basically declaring the module in a @types package and using the following tsconfig.json

{
"compilerOptions": {
    "module": "validate.js",
    "noImplicitAny": true,
    "typeRoots": [
        "./node_modules/@types"
    ]
}
}

But this get's really hacky and will probably not be merged by @DefinitelyTyped

TL;DR the best way probably is to use one of the forks with the correct types as a dependency instead, as proposed in this thread: https://www.reddit.com/r/typescript/comments/cpe0u1/overriding_a_third_party_librarys_exported_types/

Maybe someone with more time can try what works...

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants