我正在努力获得JQuery和SignalR的基本功能,以便在Vs2012中使用TypeScript,这是一个长期以来可以获得Iam的地方。使用来自DefinitelyTyped @ GitHub的最新JQuery和SignalR,我甚至无法编译它,更不用说让我的代码编译而没有JQuery开始spas out并至少报告300个错误,首先是因为密钥必须从数字和然后因为仿制药显然似乎没有支持。
信息:
----------- Greeter Generics Class-游乐场示例------------------------
class Greeter<T> {
greeting: T;
constructor(message: T) {
this.greeting = message;
}
greet() {
return this.greeting;
}
}
var greeter = new Greeter<string>("Hello, world");
var button = document.createElement('button');
button.innerText = "Say Hello";
button.onclick = function () {
alert(greeter.greet());
}
document.body.appendChild(button);
----------- Greeter Class - 游乐场示例------------------------
class Greeter {
greeting: string;
constructor(message: string) {
this.greeting = message;
}
greet() {
return "Hello, " + this.greeting;
}
}
var greeter = new Greeter("world");
var button = document.createElement('button');
button.innerText = "Say Hello";
button.onclick = function() {
alert(greeter.greet());
}
document.body.appendChild(button);
-----------我的代码 - 不是它应该重要------------------------
interface sandboxCommunication extends HubConnection {
addNewMessageToPage: Function;
newContosoChatMessage: Function;
}
interface SignalR {
chat: HubConnection;
sbconnection: sandboxCommunication;
}
class SandBox {
// Constructor
constructor() {
var sbconnection = $.connection.sbconnection;
// Declare a function on the chat hub so the server can invoke it
sbconnection.addNewMessageToPage = function (name, message) {
$('#messages').append('<li><strong>' + name
+ '</strong>: ' + message + '</li>');
};
$.connection.hub.start().done(function () {
$("#broadcast").click(function () {
// Call the chat method on the server
sbconnection.newContosoChatMessage($('#msg').val());
});
});
function connectionReady() {
$('#messages').append('<li><strong>' + "Server: "
+ '</strong>: ' + "Connected" + '</li>');
};
$.connection.hub.error(function () {
alert("An error occured");
});
$.connection.hub.start()
.done(function () {
$.connection.hub.start().done(function () {
$("#broadcast").click(function () {
// Call the chat method on the server
sbconnection.newContosoChatMessage($('#msg').val());
});
}).done(connectionReady);
})
.fail(function () {
alert("Could not Connect!");
});
$.connection.hub.url = 'http://localhost:56808/SBCHub'
$.connection.hub.start();
}
}
--------------------错误-------------------------- ----
Error 1 Expected '{' D:\\.Sandbox\TypeScript\SandBox.ts 1 14 SandBox.ts
Error 2 The name 'T' does not exist in the current scope D:\\.Sandbox\TypeScript\SandBox.ts 3 26 SandBox.ts
Error 3 The name 'T' does not exist in the current scope D:\\.Sandbox\TypeScript\SandBox.ts 3 26 SandBox.ts
Error 4 The name 'T' does not exist in the current scope D:\\.Sandbox\TypeScript\SandBox.ts 3 26 SandBox.ts
Error 5 The name 'T' does not exist in the current scope D:\\.Sandbox\TypeScript\SandBox.ts 3 26 SandBox.ts
Error 6 The name 'T' does not exist in the current scope D:\\.Sandbox\TypeScript\SandBox.ts 3 26 SandBox.ts
Error 7 The property 'greeting' does not exist on value of type 'Greeter' D:\\.Sandbox\TypeScript\SandBox.ts 4 14 SandBox.ts
Error 8 The property 'greeting' does not exist on value of type 'Greeter' D:\\.Sandbox\TypeScript\SandBox.ts 7 21 SandBox.ts
Error 9 Operator '>' cannot be applied to types 'bool' and 'string' D:\\.Sandbox\TypeScript\SandBox.ts 11 15 SandBox.ts
Error 10 Supplied parameters do not match any signature of call target D:\\.Sandbox\TypeScript\SandBox.ts 11 19 SandBox.ts
Error 11 The name 'string' does not exist in the current scope D:\\.Sandbox\TypeScript\SandBox.ts 11 27 SandBox.ts
Error 12 The property 'greet' does not exist on value of type 'bool' D:\\.Sandbox\TypeScript\SandBox.ts 16 19 SandBox.ts
任何帮助将不胜感激! : - )
答案 0 :(得分:1)
似乎你没有运行TS 0.9.x(尽管你说的话)。我建议您卸载当前版本,然后从此处下载+安装版本:http://www.microsoft.com/en-us/download/details.aspx?id=34790