PathIntellisense icon indicating copy to clipboard operation
PathIntellisense copied to clipboard

Importing .ts files in .tsx.

Open MartynasZilinskas opened this issue 9 years ago • 7 comments

When import .ts in .ts or .tsx in .tsx, it doesn't add extension. That's great. But when I am using both extension files .ts and .tsx it auto completes with .ts and etc.

MartynasZilinskas avatar Jul 12 '16 07:07 MartynasZilinskas

@MartynasZilinskas: Thank you for your feedback. I could lead to problems since you can have two files with the same name but different extensions in one folder. Not sure it is a good idea to allow this. I keep it open to get more feedback for a while.

ChristianKohler avatar Sep 13 '16 20:09 ChristianKohler

@ChristianKohler I think that you misunderstood @MartynasZilinskas ... Let's say I have a file 'a.ts'.

If I try to import it from a file named 'b.ts', PathIntellisense will suggest me: import './a'

But if I try to import it from a file named 'c.tsx', PathIntellisense will suggest me: import './a.ts'

I believe this behavior is caused by the following commit https://github.com/ChristianKohler/PathIntellisense/commit/65a978816c1976c51c95721b7e31f75d8fa724d4

Here is a suggested fix https://github.com/ChristianKohler/PathIntellisense/pull/34

galman33 avatar Oct 25 '16 19:10 galman33

Hi @galman33 , thank you for your input and your pull request.

Let's say you have 4 files:

  • navbar.ts
  • navbar.tsx
  • navbar.scss
  • navbar.html

When you want to import these files into main.ts you would like to have it like this:

import {} from "./navbar"

import {} from "./navbar.tsx"

import {} from "./navbar.scss"

import {} from "./navbar.html"

So the rule is pretty simple at the moment:

  • Same extension ? strip extension : otherwise don't

If I would strip the extension from the .tsx file it would be a naming clash with the .ts file.

In your example you suggested that if you would import a .ts into a .tsx, the extension should be stripped off, right? That would actually break this simple rule and would need some additional logic in place like:

  • same extension || file extension ts and tsx vice versa.. ?? strip extension : otherwise don't

About the pull request: I added a comment to your pull request. Actually breaks the if clause. See comment in pull request.

@galman33 What do you think? Not sure I misunderstood @MartynasZilinskas .

@MartynasZilinskas what do you say?

ChristianKohler avatar Oct 25 '16 21:10 ChristianKohler

@ChristianKohler Correct me if I am wrong, but I think that it depends on the way you configured Webpack (in resolve/extensions) and not on the extension of the current file (?).

Maybe we can add a setting to Path Intellisense which looks like: "path-intellisense.extensionsToStripOnImport": ['tsx', 'ts'],

galman33 avatar Oct 25 '16 21:10 galman33

@galman33 is actually right, @MartynasZilinskas meant the exact situation that @galman33 explained. And the both extensions should be stripped, because they produce same output (.js file), only the processing is different according to extension, i.e. you can use JSX syntax in .tsx file.

So, conclusion is that we still need the functionality to strip both extensions.

DovydasNavickas avatar Oct 26 '16 14:10 DovydasNavickas

Does this reproduce with regular JSX files? I think this behavior should be consisten across files alike. I don't React, so I don't know what React would import if it finds two files with the same name, but different extension.

michaeljota avatar Dec 01 '16 13:12 michaeljota

why can't resloved ? have same name files use setting to Path Intellisense which looks like:

"path-intellisense.extensionsToStripOnImport": [
  ['tsx', 'ts'],
  ['jsx', 'js'],
] 

this have other problems ?

it finds two files with the same name use default first . ['jsx','js'] , index.js & index.jsx use index.jsx ['js','jsx'] , index.js & index.jsx use index.js

how about this

wsz7777 avatar Dec 09 '19 08:12 wsz7777