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

Add TypeScript definitions for tcomb-form #394

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

Conversation

RedRoserade
Copy link

This adds TypeScript definitions for tcomb-form, based on the Guide.

A devDependency on @types/react was added for the Form component and the other Component classes.

Similar to the type definition for tcomb-validation, gcanti/tcomb-validation#63, this extends the tcomb module, adding getTcombFormFactory and getTcombFormOptions to t.Type<T>.

I am, however, not sure if the type definitions are 100% complete or accurate. I'd appreciate your feedback to improve them.

@gcanti
Copy link
Owner

gcanti commented Aug 1, 2017

@RedRoserade this is great, thanks for taking the time to write this definitions

@bialasik
Copy link

Why it's still doesn't merged?


declare namespace form {

type PlaceholderOptions = 'auto' | 'none';
Copy link
Owner

Choose a reason for hiding this comment

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

type PlaceholderOptions = 'auto' | 'none' | 'labels';

labels is the default value

auto: 'labels',


type PlaceholderOptions = 'auto' | 'none';

type ErrorMessage = JSX.Element | ((value: any, path: Path, context: any) => JSX.Element);
Copy link
Owner

Choose a reason for hiding this comment

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

Is this type useful? Seems defined but not used

type ErrorMessage = JSX.Element | ((value: any, path: Path, context: any) => JSX.Element);

type TcombI18NOptions = {
add: string;
Copy link
Owner

Choose a reason for hiding this comment

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

Not sure but I think they could be React.ReactNodes instead of strings

interface TemplateLocals {
attrs: any;
config: any;
context: any;
Copy link
Owner

Choose a reason for hiding this comment

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

Is it possible to remove some any here? What about using object

attrs: object;
config: object;
context: object;

label?: React.ReactNode;
onChange: (value: any) => void;
path: Path;
typeInfo: any;
Copy link
Owner

Choose a reason for hiding this comment

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

Based on

return {
typeInfo could be of type

type TypeInfo = {
  type: t.Type<any>,
  isMaybe: boolean,
  isSubtype: boolean,
  innerType: t.Type<any>,
  getValidationErrorMessage?: (value: any, path: Path, context: any) => React.Node
}

@gcanti
Copy link
Owner

gcanti commented May 15, 2018

My bad, there was a pending review which I didn't submit at the time, sorry @RedRoserade

@marcodafonseca
Copy link

Can the above change request please be acted on? It would be really helpful to have Typescript definitions enabled.

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.

4 participants