Vs2012 で JQuery と SignalR の基本機能を TypeScript と連携させようとしています。DefinedTyped @ GitHub の最新の JQuery と SignalR を使用すると、コードをコンパイルするどころか、コンパイルすることさえできません。次に、明らかにサポートされていないように見えるジェネリックが原因です。
情報:
- 最新の (0.9.0.1) TypeScript を使用しています
- 私は最新の間違いなく型付けされた JQuery ライブラリを使用しています (他のコードなしでテストされ、同じ結果)
- TypeScript のビルド オプションを ES5 および ES3 に設定してみました
- 他のバージョンの JQuery を使用してみましたが、より良い結果は得られませんでした。
- すべてが基本的な JavaScript で問題なく動作します。
- TypeScript はコンパイルできるため、基本的な typescript コードを生成できます。
- TypeScript は PlayGround の例をジェネリックでコンパイルすることはできませんが、クラスの例をジェネリックなしでコンパイルすることはできます。
- 一番下のエラー - ss を投稿できなかったため、コードとして追加されました。
-----------Greeter Generics クラス - Playground の例------------------------
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 クラス - Playground の例------------------------
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
どんな助けでも大歓迎です!:-)