vscode-auto-close-tag icon indicating copy to clipboard operation
vscode-auto-close-tag copied to clipboard

TypeScript Generics: Adds closing "Tag" to type specifier

Open AncientGrief opened this issue 8 years ago • 19 comments

Using VS Code and editing a TS File and using generics, the plugin is adding a closing HTML-Tag to the generics type specifier, e.G.:

clicked = new EventEmitter<string></string>()

It's okay for Angular2 TS files containing inline HTML templates, but it should somehow detect if I am editing a generic class instantiation.

Edit: vscodeplerr

AncientGrief avatar Nov 25 '16 19:11 AncientGrief

Hi @AncientGrief , currently the extension has not supported this scenario. A quick workaround is to only enable auto-close-tag on certain languages. In VS Code, File->Preferences->User Settings, open the settings.json. Then add config like below:

{
    "auto-close-tag.activationOnLanguage": [
        "html",
        "xml",
        "javascript",
        "javascriptreact",
        "typescriptreact"
    ]
}

Thus, the auto-close-tag will enabled on .tsx file and disabled on .ts file. Let me know whether it works for you.

formulahendry avatar Nov 26 '16 03:11 formulahendry

@formulahendry I'm having this exact same issue. I use TypeScript with React, which means all my tags are living with my types, and I cannot just turn off Auto Close in my '.tsx' files.

It's a very nice extension, nevertheless. Thank you for the effort.

blaesus avatar Mar 15 '17 03:03 blaesus

Speaking of which, I find that the "Sublime 3" mode seems an acceptable workaround me though...

blaesus avatar Mar 15 '17 04:03 blaesus

@andyshuhsin , thanks for your feedback. Yes, Sublime Text Mode would be one of the workaround. Also, you could use Alt+. (Command+Alt+. for Mac) to trigger close tag manually.

formulahendry avatar Mar 15 '17 04:03 formulahendry

I see the same thing with flow annotations in .jsx files. I have basically gotten used to hitting undo (cmd-z) to clear the close tag after it's auto-generated (on mac).

warmbowski avatar Apr 17 '17 17:04 warmbowski

I've just disabled on TS. I don't write many tags there and I do write a lot of generics. Still a time-saving extension, and free -- so I can't complain. Would be neat if it could only complete tags in strings for languages like TS and JS.

fluffynuts avatar Jun 23 '17 18:06 fluffynuts

I have the same issue using Flow.

faceyspacey avatar Jul 02 '17 10:07 faceyspacey

Would this issue be addressed (without workarounds)?

feafarot avatar Apr 23 '18 22:04 feafarot

@warmbowski ,very witty.😁

chenxiaochun avatar Nov 08 '18 01:11 chenxiaochun

same here, June 2019,..

webia1 avatar Jun 25 '19 14:06 webia1

I'm seeing this issue with JSX generics as well, which lead me to disable the plugin:

for example using Apollo Query, you can write generic JSX as such:

<Query<{name:string}>>
</Query>

the plugin constantly attempts to rename the closing tag with the generic, causing errors. As far as I can tell there isn't a way out of this issue currently?

dontsave avatar Jul 08 '19 20:07 dontsave

I see the same thing with flow annotations in .jsx files. I have basically gotten used to hitting undo (cmd-z) to clear the close tag after it's auto-generated (on mac).

Can confirm ctrl+z works as expected here on Windows.

jonnyasmar avatar Oct 31 '19 19:10 jonnyasmar

Any updates here? Can't this be made configurable?

Morriz avatar Mar 17 '20 16:03 Morriz

It'd be great if there's an option for TS users to config whether close tags or not depending on what the tag name is. For instance <T> Array<string>, etc.. Sublime mode can be the plan B, but it's uncomfortable still from the fact that you still need to type additional "</". Seems like pressing Cmd-z(MAC) is simple-er Thanks for the great extension thou.

brandonwie avatar Jun 29 '20 01:06 brandonwie

Apparently it's best to just disable this extension altogether. The included typescript extension for vscode already autocloses tags in JSX/TSX. So if you just need the auto-close-tag extension for that you can disable it.

Relevant settings are: javascript.autoClosingTags and typescript.autoClosingTags.

rhyek avatar Apr 26 '21 18:04 rhyek

@formulahendry why still include javascript and typescript within the defaults? Unless I've somehow retained settings from 5 years ago.

Anyway, removing the languages as shown above worked.

tvkit avatar Jun 27 '21 02:06 tvkit

I just ran into this problem and the solution is to simply uninstall the Auto Close Tag extension - you probably won't need it. VSCode auto closes tags by itself and you will no longer be having the problem of generic type definitions in Typescript files being auto-closed too. (Then you also won't need any settings for auto-close-tag.)

j-hannes avatar Feb 06 '22 09:02 j-hannes

I had the same problem, so I had to shut it down<Auto Close Tag>,

245563229 avatar Oct 11 '22 06:10 245563229

Hi @AncientGrief , currently the extension has not supported this scenario. A quick workaround is to only enable auto-close-tag on certain languages. In VS Code, File->Preferences->User Settings, open the settings.json. Then add config like below:

{
    "auto-close-tag.activationOnLanguage": [
        "html",
        "xml",
        "javascript",
        "javascriptreact",
        "typescriptreact"
    ]
}

Thus, the auto-close-tag will enabled on .tsx file and disabled on .ts file. Let me know whether it works for you.

Hi @formulahendry , I just configured the following configurations in the settings.json file, but I still encounter the issue shown in the attached GIF file when using TypeScript syntax in the script tag of my Vue file. Is there any solution to this?

Screen-2023-12-28-163604

eminem-xiao avatar Dec 28 '23 08:12 eminem-xiao