所以我从这里改编了这段代码用于学习目的:
"use strict";
/// <reference path="./definitelyTyped/node/node.d.ts" />
import * as net from "net";
let sockets: net.Socket[] = [];
/*
* Cleans the input of carriage return, newline
*/
function cleanInput(data: Buffer): string {
return data.toString().replace(/(\r\n|\n|\r)/gm, "");
}
/*
* Method executed when data is received from a socket
*/
function receiveData(socket: net.Socket, data: Buffer): void {
let cleanData: string = cleanInput(data);
if (cleanData === "@quit") {
socket.end("Goodbye!\r\n");
} else {
for (var i: number = 0; i < sockets.length; i++) {
if (sockets[i] !== socket) {
sockets[i].write(data);
}
}
}
}
/*
* Method executed when a socket ends
*/
function closeSocket(socket: net.Socket): void {
let i: number = sockets.indexOf(socket);
if (i !== -1) {
sockets.splice(i, 1);
}
}
/*
* Callback method executed when a new TCP socket is opened.
*/
function newSocket(socket: net.Socket): void {
sockets.push(socket);
socket.write("Welcome to the Telnet server!\r\n");
socket.on("data", function(data: Buffer): void {
receiveData(socket, data);
});
socket.on("end", function(): void {
closeSocket(socket);
});
}
// create a new server and provide a callback for when a connection occurs
let server: net.Server = net.createServer(newSocket);
// listen on port 4444
server.listen(4444);
console.log("started");
我正在使用这些tslint.json规则在此文件上运行tslint 。
这就是我得到的:
app.ts[10, 1]:缺少“使用严格”
app.ts[17, 1]:缺少“使用严格”
app.ts[33, 1]:缺少“使用严格”
app.ts[43, 1]:缺少“使用严格”
我的理解是,"use string";
文件的第一行应该是整个文件的全局。然而,每个函数都会产生一条消息。我错过了什么吗?