mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 21:36:50 -05:00
Use stricter types for event bodies
This commit is contained in:
@@ -232,7 +232,7 @@ namespace ts.projectSystem {
|
||||
return this.executeCommand(<T>request);
|
||||
}
|
||||
|
||||
public event<T>(body: T, eventName: string) {
|
||||
public event<T extends object>(body: T, eventName: string) {
|
||||
this.events.push(server.toEvent(eventName, body));
|
||||
super.event(body, eventName);
|
||||
}
|
||||
|
||||
@@ -502,7 +502,7 @@ namespace ts.server {
|
||||
constructor(options: IoSessionOptions) {
|
||||
const { host, eventPort, globalTypingsCacheLocation, typingSafeListLocation, typesMapLocation, npmLocation, canUseEvents } = options;
|
||||
|
||||
const event: Event | undefined = (body: {}, eventName: string) => {
|
||||
const event: Event | undefined = (body: object, eventName: string) => {
|
||||
if (this.constructed) {
|
||||
this.event(body, eventName);
|
||||
}
|
||||
@@ -551,7 +551,7 @@ namespace ts.server {
|
||||
this.constructed = true;
|
||||
}
|
||||
|
||||
event<T>(body: T, eventName: string): void {
|
||||
event<T extends object>(body: T, eventName: string): void {
|
||||
Debug.assert(this.constructed, "Should only call `IOSession.prototype.event` on an initialized IOSession");
|
||||
|
||||
if (this.canUseEvents && this.eventPort) {
|
||||
@@ -572,7 +572,7 @@ namespace ts.server {
|
||||
}
|
||||
}
|
||||
|
||||
private writeToEventSocket(body: {}, eventName: string): void {
|
||||
private writeToEventSocket(body: object, eventName: string): void {
|
||||
this.eventSocket.write(formatMessage(toEvent(eventName, body), this.logger, this.byteLength, this.host.newLine), "utf8");
|
||||
}
|
||||
|
||||
|
||||
@@ -239,14 +239,14 @@ namespace ts.server {
|
||||
}
|
||||
}
|
||||
|
||||
export type Event = <T>(body: T, eventName: string) => void;
|
||||
export type Event = <T extends object>(body: T, eventName: string) => void;
|
||||
|
||||
export interface EventSender {
|
||||
event: Event;
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export function toEvent(eventName: string, body: {}): protocol.Event {
|
||||
export function toEvent(eventName: string, body: object): protocol.Event {
|
||||
return {
|
||||
seq: 0,
|
||||
type: "event",
|
||||
@@ -409,7 +409,7 @@ namespace ts.server {
|
||||
this.host.write(formatMessage(msg, this.logger, this.byteLength, this.host.newLine));
|
||||
}
|
||||
|
||||
public event<T>(body: T, eventName: string): void {
|
||||
public event<T extends object>(body: T, eventName: string): void {
|
||||
this.send(toEvent(eventName, body));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user