Port some amount of code to typescript
This commit is contained in:
30
WebsocketTest.ts
Normal file
30
WebsocketTest.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
// @ts-ignore
|
||||
const Websocket = require('ws');
|
||||
|
||||
const ws = new Websocket('ws://localhost:8191');
|
||||
ws.on('open', function open() {
|
||||
ws.send('something');
|
||||
});
|
||||
|
||||
interface Animal {
|
||||
doNoise(): void;
|
||||
}
|
||||
|
||||
class Dog implements Animal {
|
||||
doNoise(): void {
|
||||
console.log("woof");
|
||||
}
|
||||
}
|
||||
|
||||
class Cat implements Animal {
|
||||
doNoise(): void {
|
||||
console.log("meow");
|
||||
}
|
||||
}
|
||||
|
||||
const dog = new Dog();
|
||||
dog.doNoise();
|
||||
const cat = new Cat();
|
||||
cat.doNoise();
|
||||
let animals: Animal[] = [dog, cat];
|
||||
animals.forEach(animal => animal.doNoise());
|
Reference in New Issue
Block a user