Skip to content

Typescript compiler should compile files regardless of extension #9839

Closed
@haroldcampbell

Description

@haroldcampbell

I'd like suggest the addition of a feature that would allow the typescript compiler to compile files regardless of their extension.

This is a non-breaking feature.

*The scenario (with Typescript 1.8.10) *
When working with rails, I have preprocessors that need to use an .erb file extension. This breaks the compilation as tsc doesn't support .erb file extensions.

Code
Presently, if we have a file called foo.ts.erb, with the code:

class foo {
    constructor() {
        this.helloWorld();
    }
    helloWorld() {
        console.log("<%= 'hello from rails' %>")
    }
}

It fails to compile.

The code is vanilla ts with some additional 'stuff' for the erb processor. The additional .erb shouldn't affect the generation of the .js file, as the contents of the file is still valid TypeScript code.

Expected behavior:
The compiler should be able to emit the following javascript code in a file called foo.js.erb

var foo = (function () {
    function foo() {
        this.helloWorld();
    }
    foo.prototype.helloWorld = function () {
        console.log("<%= 'hello from rails' %>");
    };
    return foo;
}());

Actual behavior:
Presently the compiler fails with the following message: error TS6054: File 'foo.ts.erb' has unsupported extension. The only supported extensions are '.ts', '.tsx', '.d.ts'.

Thanks for your time

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already createdSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions