question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is it possible to wrap it with simple typings for TypeScript?

See original GitHub issue

Trying to use tcomb-form-native with typescript.

import * as t from 'tcomb-form-native';
let Form = t.form.Form;

Error:(3, 20) TS2656: Exported external package typings file ‘…/node_modules/tcomb-form-native/index.d.ts’ is not a module. Please contact the package author to update the package definition.

Error:(17, 14) TS2339: Property ‘form’ does not exist on type ‘typeof ‘tcomb-form-native’’.

Please suggest simple index.d.ts. Somehow wrap all in “any”? My newbie attempts didn’t help:

declare module 'tcomb-form-native' {
  import * as React from 'react';

  class Form extends React.Component<any, any> {
  }

  let t: any;

  // if the module has a default export
  export default t; // where t is the actual default export


  /* Definistions from tcomb lib */

  type Predicate<T> = (x: T) => boolean;
  type TypeGuardPredicate<T> = (x: any) => x is T;

  interface Type<T> extends Function {
...
}

No success even with this article: https://templecoding.com/blog/2016/03/31/creating-typescript-typings-for-existing-react-components/

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:1
  • Comments:6

github_iconTop GitHub Comments

4reactions
akailacommented, May 20, 2020

Can we integrate this into the library? Most people are using typescript these days and not having typings for this is a big inhibiter in usage. Thanks in advance.

2reactions
alexicumcommented, Jul 1, 2016

tcomb-form-native.d.zip

Here is tcomb-form-native.d.ts

It is just cheating TS compiler…

import TCombFormNative = TComb;

declare namespace TComb {
  import React = __React;

  export interface FormComponentClass {
    Form: React.ComponentClass<any>;
  }

  export interface tcomb {
    form: FormComponentClass;
  }
}

declare var t: TCombFormNative.tcomb;

declare module 'tcomb-form-native' {
  import TCombFormNative = TComb;
  //export = TCombFormNative;
  export = t;
}

Put it into: .\typings_local\tcomb-form-native.d.ts

then install with typings by command: typings install --save --global file:.\typings_local\tcomb-form-native.d.ts

Using it with https://auth0.com/blog/2016/06/15/adding-authentication-to-react-native-using-jwt/ https://github.com/jeffreylees/reactnative-jwts/blob/master/index.ios.js

import * as t from 'tcomb-form-native';
let Form = t.form.Form;
let Person = t.struct({
  username: t.Str,
  password: t.Str
});

render() {
    return (
...
        <View style={styles.row}>
          <Form
            ref={(form: any) => this.ctrls.form = form}
            type={Person}
            options={options}
          />
        </View>
...
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Typescript object wrapping, typings and generics [duplicate]
It gives the possibility to keep clever typings and mainly code completion when using some dynamic patterns. Now, it's still a choice to...
Read more >
Documentation - Advanced Types - TypeScript
This page lists some of the more advanced ways in which you can model types, it works in tandem with the Utility Types...
Read more >
The definitive guide to typing functions in TypeScript
The definitive guide to typing functions in TypeScript ; Below is a simple function called subtraction ; This subtraction ; When we paste...
Read more >
A typed chain: exploring the limits of TypeScript
Update (2020): it is now possible to correctly type _.chain by overloading the type of this on the wrapper interface. This is how...
Read more >
How to Use Wrappers in Typescript React - Twilio
With that said, how can you write code as efficiently and clean as ... how to use wrappers for custom components in a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found