Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

types vs typings #41

Closed
TrejGun opened this issue Feb 17, 2020 · 16 comments
Closed

types vs typings #41

TrejGun opened this issue Feb 17, 2020 · 16 comments
Labels

Comments

@TrejGun
Copy link

TrejGun commented Feb 17, 2020

as Typescriopt doc says

If you still can't find it, check if it bundles its own typings. This is usually provided in a "types" or "typings" field in the package.json, or just look for any ".d.ts" files in the package and manually include them with a /// <reference path="" />.

but in fact I have problem with typings

it works with config (actually only "ts" section is enough, alwaysTryTypes could be any)

  "settings": {
    "import/resolver": {
      "ts": {
        "alwaysTryTypes": true
      },
      "node": {
        "extensions": [".js", ".jsx", ".ts", ".tsx"],
      }
    }
  }

and does not work (is highlighted) with

  settings: {
    "import/resolver": {
      node: {
        extensions: [".js", ".jsx", ".ts", ".tsx"],
      },
    },
  },

you can try these configs on this code (package)

import React from "react";
import {FieldRenderProps} from "react-final-form";
@TrejGun
Copy link
Author

TrejGun commented Feb 17, 2020

wait i'm confused myself. so if "ts" section is not present then this resolver should not work. right?
then why types for react are resolved without "ts" section?

Screen Shot 2020-02-17 at 11 55 20 AM

Screen Shot 2020-02-17 at 11 55 34 AM

Look I just want it to be consistent
There are types for react in @types/react and types for react-final-form inside the package but I can't configure eslint to see them both at the same time

@JounQin
Copy link
Collaborator

JounQin commented Feb 17, 2020

Why not use extensions like following?

{
  "import/resolver": {
    "node": {
      "extensions": [".ts", ".tsx", ".js", ".jsx"]
    }
  }
}

And please provide a minimal and runnable reproduction, I can not offer any help before debugging.

@TrejGun
Copy link
Author

TrejGun commented Feb 17, 2020

@JounQin thanks for your reply
here is minimal example
https://github.com/TrejGun/eslint-typescript-bug

@JounQin
Copy link
Collaborator

JounQin commented Feb 17, 2020

@TrejGun Then what are the steps to reproduce? I don't quite understand the problem.

@TrejGun
Copy link
Author

TrejGun commented Feb 17, 2020

steps

1 git clone https://github.com/TrejGun/eslint-typescript-bug.git
2 npm i
3 npm run bootstrap
4 npm run lint

result

@eslint-typescript-bug/package: Warning: React version not specified in eslint-plugin-react settings. See https://github.com/yannickcr/eslint-plugin-react#configuration .
@eslint-typescript-bug/package: /Users/trejgun/projects/eslint-typescript-bug/packages/test/src/index.tsx
@eslint-typescript-bug/package:   2:9  error  FieldRenderProps not found in 'react-final-form'  import/named
@eslint-typescript-bug/package: ✖ 1 problem (1 error, 0 warnings)

this error message should not be there because types for 'react-final-form' are . present in the module

@JounQin
Copy link
Collaborator

JounQin commented Feb 17, 2020

I tried DEBUG=eslint-import-resolver-ts npm run lint, there is even no log from this resolver, and after remove node section, it works:

$ eslint . --fix --ext .js,.jsx,.ts,.tsx
Warning: React version not specified in eslint-plugin-react settings. See https://github.com/yannickcr/eslint-plugin-react#configuration .
  eslint-import-resolver-ts looking for: react +0ms
  eslint-import-resolver-ts failed to init tsconfig-paths: Missing baseUrl in compilerOptions +6ms
  eslint-import-resolver-ts looking for: @types/react +4ms
  eslint-import-resolver-ts matched node path: /workspace/eslint-typescript-bug/node_modules/@types/react/index.d.ts +1ms
  eslint-import-resolver-ts looking for: csstype +1s
  eslint-import-resolver-ts matched node path: /workspace/eslint-typescript-bug/node_modules/csstype/index.d.ts +2ms
  eslint-import-resolver-ts looking for: prop-types +1ms
  eslint-import-resolver-ts looking for: @types/prop-types +2ms
  eslint-import-resolver-ts matched node path: /workspace/eslint-typescript-bug/node_modules/@types/prop-types/index.d.ts +2ms
  eslint-import-resolver-ts looking for: react-final-form +12ms
  eslint-import-resolver-ts matched node path: /workspace/eslint-typescript-bug/node_modules/react-final-form/typescript/index.d.ts +2ms
  eslint-import-resolver-ts looking for: react +37ms
  eslint-import-resolver-ts looking for: @types/react +1ms
  eslint-import-resolver-ts matched node path: /workspace/eslint-typescript-bug/node_modules/@types/react/index.d.ts +2ms
  eslint-import-resolver-ts looking for: final-form +0ms
  eslint-import-resolver-ts matched node path: /workspace/eslint-typescript-bug/node_modules/final-form/dist/index.d.ts +2m

So I don't think your issue is related to eslint-import-resolver-typescript itself, and please take a look at #31 and import-js/eslint-plugin-import#1282

@JounQin
Copy link
Collaborator

JounQin commented Feb 17, 2020

And the sequence of import/resolver does mater.

eslint-import-resolver-typescript should always take higher priority, but it understand TypeScript better then eslint-import-resolver-node.

@JounQin
Copy link
Collaborator

JounQin commented Feb 17, 2020

@TrejGun eslint-import-resolver-node resolves react-final-form to node_modules/react-final-form/dist/react-final-form.cjs.js, there is no FieldRenderProps(interface of TypeScript) at all.

@JounQin JounQin closed this as completed Feb 17, 2020
@TrejGun
Copy link
Author

TrejGun commented Feb 17, 2020

@JounQin sorry I did not get

node_modules/react-final-form/dist/react-final-form.cjs.js is js file, and package.json says "typings": "typescript/index.d.ts", for me this is perfectly fine

"extensions": [".ts", ".tsx", ".js", ".jsx"] this part i got, but . still can't make it work

after remove node section, it works - does not work for me can you please post full config?

@JounQin
Copy link
Collaborator

JounQin commented Feb 18, 2020

node_modules/react-final-form/dist/react-final-form.cjs.js is js file, and package.json says "typings": "typescript/index.d.ts", for me this is perfectly fine

Yes, and eslint-plugin-import can only resolve one file, so if eslint-import-resolver-node resolves a js file first, eslint-import-resolver-typescript will not be used at all.

after remove node section, it works - does not work for me can you please post full config?

You should only have one .eslintrc file in root directory, try remove .eslintrc in subfolders, and overrides feature of ESLint is the alternative.

@TrejGun
Copy link
Author

TrejGun commented Feb 18, 2020

please post your config or better make a PR to my code. I can't make react and final-form types work at the same time

@JounQin
Copy link
Collaborator

JounQin commented Feb 18, 2020

@TrejGun Open in Gitpod

@TrejGun
Copy link
Author

TrejGun commented Feb 18, 2020

thanks a lot.
this is exactly what i mean
you replaced

import React from "react";

with

import * as React from "react";

and this works
but in my initial case I say I would like to have

import React from "react";
import {FieldRenderProps} from "react-final-form";

see screenshots ^^^
but for some reaso I can't. Is it a bug or what?

@JounQin
Copy link
Collaborator

JounQin commented Feb 19, 2020

#31 (comment)

I've mentioned this related question above at #41 (comment) and README.

There's no reason to enable import/default nor import/named for .ts IMO. Please read related context by yourself.

@TrejGun
Copy link
Author

TrejGun commented Feb 19, 2020

ok i got your point, thanks for your patience

@JounQin
Copy link
Collaborator

JounQin commented Feb 19, 2020

I can't get your point, you can always use overrides in ESLint config.

I'm not going to answer things beyond scope of this resolver. (I've answered in the related issue and README.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants