实例化扩展类的接口

时间:2017-01-04 11:29:57

标签: typescript typescript-typings

我正在尝试移植一些试图创建public static void main(String[] args) { JFrame Frame = new JFrame(); JTabbedPane jTabbedPane1 = new javax.swing.JTabbedPane(); JScrollPane jScrollPane1 = new javax.swing.JScrollPane(); JPanel jPanel1 = new javax.swing.JPanel(); JButton jButton1 = new javax.swing.JButton(); JButton jButton2 = new javax.swing.JButton(); JScrollPane jScrollPane2 = new javax.swing.JScrollPane(); JTable jTable1 = new javax.swing.JTable(); Frame.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jPanel1.setLayout(new javax.swing.BoxLayout(jPanel1, javax.swing.BoxLayout.Y_AXIS)); jButton1.setText("jButton1"); jPanel1.add(jButton1); jButton2.setText("jButton2"); jPanel1.add(jButton2); jTable1.setModel(new javax.swing.table.DefaultTableModel( new Object[][]{ {null, null, null, null, null, null, null, null, null, null, null, null}, {null, null, null, null, null, null, null, null, null, null, null, null}, {null, null, null, null, null, null, null, null, null, null, null, null}, {null, null, null, null, null, null, null, null, null, null, null, null}, {null, null, null, null, null, null, null, null, null, null, null, null}, {null, null, null, null, null, null, null, null, null, null, null, null}, {null, null, null, null, null, null, null, null, null, null, null, null}, }, new String[]{ "Title 1", "Title 2", "Title 3", "Title 4" } )); jScrollPane2.setViewportView(jTable1); jPanel1.add(jScrollPane2); jScrollPane1.setViewportView(jPanel1); jTabbedPane1.addTab("tab2", jScrollPane1); Frame.setContentPane(jTabbedPane1); Frame.setVisible(true); } 实例的代码。但是打字稿抱怨:

  

[ts]属性'ServerResponse'在类型'typeof“http”'上不存在。

我通过控制台检查过,http.ServerResponse绝对是一个可以在运行时实例化的类。

http.ServerResponse @types/node内键入:

http.ServerResponse

其中export interface ServerResponse extends stream.Writable` 解析为 stream.Writable

那么,有没有办法解决这个问题(当一个接口扩展一个类时)或者只是一个明确类型的输入问题?

1 个答案:

答案 0 :(得分:0)

这对我有用:

import http = require("http");
import stream = require("stream");

let response = new stream.Writable() as http.ServerResponse;