Skip to content
This repository has been archived by the owner on Nov 27, 2023. It is now read-only.

type definitions without module #624

Closed
artyomsv opened this issue Sep 21, 2018 · 9 comments
Closed

type definitions without module #624

artyomsv opened this issue Sep 21, 2018 · 9 comments

Comments

@artyomsv
Copy link

Hi,

I have multiple Scenarios and not sure if your library support them:

  • I would like to generate dts files for multiple JSX with single command
  • I would like to generate index.d.ts file for each widget, but I do not want to declare module.

Do you have and examples how I can achieve this with react2dts?

Thanks in advance!

Artyom

@KnisterPeter
Copy link
Owner

Hi @artyomsv,
all current possible cases are in the various unit tests. Please have a look if there is something which fulfills your requirement. I'm not sure what you mean with do not want to declare module.

Right now it is only possible to create dts for one file at once. But it should be quite simple to eiter loop through them with a simple bash command or use the JS API.

@artyomsv
Copy link
Author

@KnisterPeter thanks for quick reply
Regarding declaring the module here is an example:
If I use your tool for JSX file I get something like this:

declare module 'name' {
    import * as React from 'react';

    export interface BaseInputCssModule {
       ...
    }

    export interface BaseInputProps {
        .......
    }

    const BaseInput: React.SFC<BaseInputProps>;

    export default BaseInput;

}

In my case I just want to place dts file together with my widget so I would expect to have index.d.ts file like:

export interface BaseInputCssModule {
  ...
}

export interface BaseInputProps {
  ...
}

declare const BaseInput: React.SFC<BaseInputProps>;

export default BaseInput;

@KnisterPeter
Copy link
Owner

Just add --top-level-module to your cmdline

@bartholomews
Copy link

Hello, I am having the same issue, --top-level-module seems to be ignored and it defaults same as I would do react2dts --module-name moduleName, is there something I am missing? Thanks

@KnisterPeter
Copy link
Owner

@bartholomews I have no clue. Can you please add your whole commandline you execute with all parameters and any output you get to this issue?

@bartholomews
Copy link

@sinnerschrader I think I have found the issue, it's defaulting only if the flag is set without value, if followed by any value it seems to work:

react2dts-top-level-module-example

So it's not a big deal for us I think 👍

@KnisterPeter
Copy link
Owner

@bartholomews Intersting find. I'll flag this as bug as it should be fixed. But you already have your workaround. Thanks for sharing.

@KnisterPeter KnisterPeter added bug and removed question labels May 2, 2019
@jamesopti
Copy link

I ran into the same issue! Here was my workaround:

#
# Helper script to generate a master Typescript definition file.
#
INPUT_FILES=src/components/*/index.js
OUTPUT_FILE=types/index.d.ts
regex='src/components/([A-Za-z]+)/index.js'

# Initialize the output file with a header
cat > $OUTPUT_FILE <<- EOM
// Type definitions for <my project>
// Project: <my project>
// Definitions by:

/// <reference types="my-project" />

EOM

# Loop through all input files and run react2dts on them,
# concatenating the output to our single output file
for file in $INPUT_FILES; do
  [[ $file =~ $regex ]]
  comp_name=${BASH_REMATCH[1]}
  $(npm bin)/react2dts --file "$file" --name $comp_name >> $OUTPUT_FILE
done

@stale
Copy link

stale bot commented Jul 29, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Jul 29, 2020
@stale stale bot closed this as completed Aug 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants