Closed
Description
Consider this code:
// myPlugin.ts
<reference path="typings/jquery/jquery.d.ts" />
// Add a plugin to the JQuery type
interface JQuery {
myPlugin():JQuery;
}
var $myEl = $('foo').myPlugin();
var $bar = $('foo').find('bar');
This works fine. The problem comes when I mix this with an external import:
// myPlugin.ts
<reference path="typings/jquery/jquery.d.ts" />
import _ = require('underscore');
// Add a plugin to the JQuery type
interface JQuery {
myPlugin():JQuery;
}
var $myEl = $('foo').myPlugin();
var $bar = $('foo').find('bar');
/// error TS2339: Property 'find' does not exist on type 'JQuery'.
This does not seem to be specific to JQuery/underscore, but happens whenever I add to an interface in the same file as an import.
I can work around this by moving the interface additions to another file:
// jquery.ext.d.ts
<reference path="typings/jquery/jquery.d.ts" />
interface JQuery {
myPlugin();
}
// myPlugin.ts
<reference path="typings/jquery/jquery.d.ts" />
<reference path="jquery.ext.d.ts" />
import _ = require('underscore');
var $myEl = $('foo').myPlugin();
var $bar = $('foo').find('bar');
Is this a bug in the compiler, or expected behavior? If it is expected, is there any documentation I can look at?
Thanks!