我想用mocha来测试我的TypeScript/Angular2项目.我试图用TS-节点描述在这里:
npm install -g ts-node
Run Code Online (Sandbox Code Playgroud)
但是跑步的时候
mocha --require ts-node/register -t 10000 ./**/*.unit.ts
Run Code Online (Sandbox Code Playgroud)
我收到一个错误
找不到模块'ts-node/register'
我在这里错过了什么?
根据你应该 的官方风格指南
避免使用下划线为私有属性和方法添加前缀.
由于我来自Java背景,我通常只使用this关键字:
export default class Device {
private id: string;
constructor(id: string) {
this.id = id;
}
public get id(): string { // [ts] Duplicate identifier 'id'.
return this.id;
}
public set id(value: string) { // [ts] Duplicate identifier 'id'.
this.id = value;
}
}
Run Code Online (Sandbox Code Playgroud)
但TypeScript编译器抱怨:[ts]重复标识符'id'.
在TypeScript构造函数中是否存在参数命名的约定或最佳实践?
编辑
抱歉,我错过了实际导致TS编译器错误的代码的基本部分.
使用TypeScript 的get和set属性会产生错误.
所以我更新了一个问题:有没有办法遵循样式指南并使用TypeScript的get/set属性?
我对Ionic框架很新.
按照文档我创建了一个像这样的搜索栏:
<ion-searchbar
[(ngModel)]="searchQuery"
[showCancelButton]="true"
(ionInput)="search($event)">
</ion-searchbar>
Run Code Online (Sandbox Code Playgroud)
ionInput当搜索栏输入已更改(包括已清除)时.
这按预期工作.
但是我想要一个不同的行为.我不想在search($event)每次输入更改时触发,但是当用户点击"输入"键或单击按钮时,我找不到发出的输出事件.
这种行为有解决方案吗?
我正在使用Apache Commons Configuration库与PropertiesConfiguration. 我的应用程序在启动后立即加载配置文件,如下所示:
public PropertiesConfiguration loadConfigFile(File configFile) throws ConfigurationNotFoundException {
try {
if (configFile != null && configFile.exists()) {
config.load(configFile);
config.setListDelimiter(';');
config.setAutoSave(true);
config.setReloadingStrategy(new FileChangedReloadingStrategy());
setConfigLoaded(true);
}
else {
throw new ConfigurationNotFoundException("Configuration file not found.");
}
} catch (ConfigurationException e) {
logger.warn(e.getMessage());
setDefaultConfigValues(config);
config.setFile(configFile);
}
return config;
}
Run Code Online (Sandbox Code Playgroud)
我的问题是,如何验证configFile,以便我可以确定该文件中没有丢失任何属性,并且稍后在我的代码中NullPointerException尝试访问属性时我不会得到 a ,例如:
PropertiesConfiguration config = loadConfig(configFile);
String rootDir = config.getString("paths.download"); // I want to be sure that this property exists right at the …Run Code Online (Sandbox Code Playgroud) 我试图使用JAX-RS从REST服务下载文件.这是我的代码,它通过发送GET请求来调用下载:
private Response invokeDownload(String authToken, String url) {
// Creates the HTTP client object and makes the HTTP request to the specified URL
Client client = ClientBuilder.newClient();
WebTarget target = client.target(url);
// Sets the header and makes a GET request
return target.request().header("X-Tableau-Auth", authToken).get();
}
Run Code Online (Sandbox Code Playgroud)
但是,我遇到将Response转换为实际File对象的问题.所以我做的是以下内容:
public File downloadWorkbook(String authToken, String siteId, String workbookId, String savePath)
throws IOException {
String url = Operation.DOWNLOAD_WORKBOOK.getUrl(siteId, workbookId);
Response response = invokeDownload(authToken, url);
String output = response.readEntity(String.class);
String filename;
// some code to retrieve the …Run Code Online (Sandbox Code Playgroud)