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

Support non-code AMD modules #279

Closed
fsoikin opened this issue Jul 28, 2014 · 8 comments
Closed

Support non-code AMD modules #279

fsoikin opened this issue Jul 28, 2014 · 8 comments
Labels
Duplicate An existing issue was already created Suggestion An idea for TypeScript

Comments

@fsoikin
Copy link

fsoikin commented Jul 28, 2014

Original issue on CodePlex: https://typescript.codeplex.com/workitem/1046

Problem

Need to require text, CSS, and other non-code things.

import template: string = require( "text!./Templates/MyTemplate.html" );

Partial workaround

Use the /// <amd-dependency path="x" /> tag.

// At the top of the file
/// <amd-dependency path="text!./Templates/MyTemplate.html" />

... <snip> ...

declare function require( path: string ): any;
var template: string = require( "text!./Templates/MyTemplate.html" );

Why workaround is not good enough

Have to type the module name twice.

@wimoy
Copy link

wimoy commented Sep 5, 2014

I ran into this issue before and worked around it by creating an ambient declaration for the module.

declare module "text!./Templates/MyTemplate.html" {
}

Now, I can load the module like this:

import Template = require("text!./Templates/MyTemplate.html")

@csnover
Copy link
Contributor

csnover commented Apr 28, 2015

This is fixed in 1.5, you can specify a name attribute on the amd-dependency comment. https://github.com/Microsoft/TypeScript/wiki/What%27s-new-in-TypeScript#amd-dependency-optional-names

@mhegazy
Copy link
Contributor

mhegazy commented Apr 28, 2015

We have talked about allowing type annotation on module imports. something like:

import * as n: any from "mod";

@RichiCoder1
Copy link

@mhegazy I would very much like that. Not only to type html imports as strings, but also for types that are "map"'d, so you don't have to write a definition to map the name to the actual type.

@mhegazy
Copy link
Contributor

mhegazy commented Apr 28, 2015

@RichiCoder1, i am interested to know what you mean by "mapped". Would that be something covered by mapping paths for module? can you take a look at #2338, and see if this fits your scenario?

@lukeapage
Copy link

is a type parameter on the amd-dependency possible? e.g.

typescript 1.4

// At the top of the file
/// <amd-dependency path="text!./Templates/MyTemplate.html" />

... <snip> ...

declare function require( path: string ): any;
var template: string = require( "text!./Templates/MyTemplate.html" );

typescript 1.5

// At the top of the file
/// <amd-dependency path="text!./Templates/MyTemplate.html" name="myTemplateHtml" />
declare var myTemplateHtml : string;
... <snip> ...

var template: string = myTemplateHtml;

typescript 1.x ?

// At the top of the file
/// <amd-dependency path="text!./Templates/MyTemplate.html" name="myTemplateHtml" type="string" />
... <snip> ...

var template: string = myTemplateHtml;

@mhegazy
Copy link
Contributor

mhegazy commented Jun 24, 2015

@lukeapage it is just a proposal at this point. it has not been implemented. if and when it is added, i do not think it will be in an /// <amd-dependency> tag. more of a syntax extension to ES6 default module import syntax.

@mhegazy mhegazy added In Discussion Not yet reached consensus and removed Needs Proposal This issue needs a plan that clarifies the finer details of how it could be implemented. labels Jun 24, 2015
@mhegazy
Copy link
Contributor

mhegazy commented Feb 20, 2016

Should be addressed by #6615

@mhegazy mhegazy closed this as completed Feb 20, 2016
@mhegazy mhegazy added Duplicate An existing issue was already created and removed In Discussion Not yet reached consensus labels Feb 20, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

7 participants