Sublime Forum

JavaScript snippets in TypeScript files?

#1

I cannot figure out why I do not have any completion of JavaScript snippets in TypeScript files? Nor can I find out how to enable it?

I would expect the same snippets to available both places.

Can someone help me out? I am a little frustrated, so I will be forever grateful.

Screenshots: JavaScript .js file

Screenshot: TypeScript .ts file

0 Likes

#2

The snippets that ship with Sublime for JavaScript are scoped to only work with JavaScript:

<snippet>
	<content><![CDATA[for (var ${20:i} = ${1:Things}.length - 1; ${20:i} >= 0; ${20:i}--) {
	${100:${1:Things}[${20:i}]}$0
}]]></content>
	<tabTrigger>for</tabTrigger>
	<scope>source.js</scope>
	<description>for (…) {…} (Improved Native For-Loop)</description>
</snippet>

The scope for JavaScript is source.js but TypeScript uses source.ts instead; so they only appear in one file and not the other.

The snippets can be found at: https://github.com/sublimehq/Packages/tree/master/JavaScript/Snippets ; so one thing you can do is download them, add them to your User package and modify them to use the appropriate scope so that they will apply to both file types.

1 Like

#3

Oh, yes. I will copy those files and modify the scope.

0 Likes