我有一个带有一些异步功能的接口.实现该接口的一些类没有任何东西需要等待,有些可能只是抛出.所有警告都有点烦人.
不在异步函数中使用await时.
是否有可能压制消息?
public async Task<object> test()
{
throw new NotImplementedException();
}
Run Code Online (Sandbox Code Playgroud)
警告CS1998:此异步方法缺少'await'运算符并将同步运行.考虑使用'await'运算符等待非阻塞API调用,或'await Task.Run(...)'在后台线程上执行CPU绑定工作.
在我的应用程序中,我非常依赖JavaScript来增强用户界面,但所有数据都来自数据库并由PHP处理.默认情况下,我使用'echo'语句来"及时"替换所需的值,如下所示:
var myVariable = <?php echo $myVariableInPHP ?>
Run Code Online (Sandbox Code Playgroud)
然而,这并没有让我感到非常优雅,我担心这些代码的稳定性和可维护性.
我在这里有其他选择吗?
对于服务器端,我使用的是Symfony 1.4 PHP框架.
谢谢,
我试图反序列化从Web API收到的JSON字符串
try
{
string r = await App.client.GetUser();
App.Authentication = JsonConvert.DeserializeObject<ApiResult>(r);
await DisplayAlert("TEST", App.Authentication.ToString(), "OK");
Application.Current.MainPage = new Schedule();
}
catch (Exception p)
{
await DisplayAlert("Getting Authentication failed", p.ToString(), "TEST");
}
Run Code Online (Sandbox Code Playgroud)
但是它给出了错误:无法将System.String转换或转换为App1.ApiResult
App.Authentication = JsonConvert.DeserializeObject<ApiResult>(r);
App.Authentication:
public static ApiResult Authentication = new ApiResult();`
Run Code Online (Sandbox Code Playgroud)
JSON字符串:
"\"{\\ "状态\\":\\ "0 \\",\\ "消息\\":{\\ "ID \\":5,\\ "姓\\":\\"约翰\\",\\ "名字\\":\\ "李四\\",\\ "电子邮件\\":\\ "testemail@gmail.com \\",\\ "密码\\":\\"testPass \\",\\ "CreationDate \\":\\ "2016-10-26T15:01:08 \\",\\ "角色ID \\":1,\\ "doorCode \\":9999 }}\""
ApiResult类:
public class ApiResult
{
public string status { get; set; …Run Code Online (Sandbox Code Playgroud) 我尝试将一些新的类型定义文件加载到我的cordova/typescript 项目中。
现在我收到以下错误:
TS2304:找不到名称“未知”。
在这些定义文件中,未知类型(关键字)没有像“any”或“string”等那样用蓝色绘制。
手动安装打字稿扩展也没有解决它。
tsconfig.json:
{
"compileOnSave": true,
"compilerOptions": {
"inlineSources": true,
"module": "system",
"noEmitOnError": true,
"noImplicitAny": false,
"out": "www/scripts/appBundle.js",
"preserveConstEnums": true,
"removeComments": true,
"sourceMap": true,
"target": "es2015"
},
"files": [ ... ]
}
Run Code Online (Sandbox Code Playgroud)
VS2017 信息:
Microsoft Visual Studio Community 2017 版本 15.9.2 VisualStudio.15.Release/15.9.2+28307.108 Microsoft .NET Framework 版本 4.7.03056
安装版本:社区
TypeScript 工具 15.9.20918.2001 适用于 Microsoft Visual Studio 的 TypeScript 工具
适用于 Apache Cordova 的 Visual Studio 工具 15.123.7408.1
我使用项目引用从“前面”和“后面”引用“共享”项目。
tsc -v: Version 3.3.3
项目结构:
./{MY_PROJECT}.code-workspace /* the only file in this level */
./back
./back/tsconfig.json
./shared/src/
./shared/
./shared/tsconfig.json
./shared/src/
./front
./front/tsconfig.json
./front/src
Run Code Online (Sandbox Code Playgroud)
我正在尝试./front/src/article-view-model.ts从共享项目中导入模块:
import Article from "@shared/src/article"; // alias path
import Article from "../../shared/src/article"; // full relative path
export default class ArticleViewModel {
}
Run Code Online (Sandbox Code Playgroud)
VS Code GUI中会立即显示以下错误:
对于别名路径:
找不到模块'@ shared / src / article'。ts(2307)
对于完整的相对路径:
尚未从源文件“ c:/ {SOMEWHERE_IN_MY_PC} /shared/src/article.ts”构建输出文件“ ../../shared/src/article”。ts(6305)
Intellisense(VS Code)确实适用于别名和相对选项:
如果我尝试忽略错误并构建,它将失败:
C:\ Program Files \ nodejs \ node_modules \ npm \ bin …
在扩展 Cheerio 库时,我实现了以下静态函数(其他扩展函数工作正常):
$.nodeType = function (elem: CheerioElement): number {
switch (elem.type) {
case "comment":
return Node.COMMENT_NODE; // <--- it fails here
case "tag":
return Node.ELEMENT_NODE; // <--- it fails here
case "text":
return Node.TEXT_NODE; // <--- it fails here
default:
return -1;
}
};
Run Code Online (Sandbox Code Playgroud)
运行时出现如下错误(编译tsc -b成功):
ReferenceError:节点未定义
Node接口是DOMAPI的一部分。因此,我意识到需要DOM在.compilerOptionstsconfig.json
但是,我仍然遇到运行时错误。
的最小相关部分tsconfig.json:
{
"compilerOptions": {
"baseUrl": ".",
"incremental": true,
"lib": [
"esnext",
"dom"
],
"module": "commonjs",
"noImplicitAny": true, …Run Code Online (Sandbox Code Playgroud) 我有一个基类和一个派生类,每个都有init函数.
当我构建派生的我想要它:
调用它的基础构造函数:
1.1.调用它的init函数
调用它自己的(派生的)init函数.
问题是派生的init函数被调用两次.
码:
class Base{
constructor() {
this.init();
}
init(){
console.log("Base init");
}
}
class Derived extends Base{
constructor() {
super();
this.init();
}
init(){
console.log("Derived init");
}
}
var obj = new Derived ();
Run Code Online (Sandbox Code Playgroud)
输出:
Derived init
Derived init
Run Code Online (Sandbox Code Playgroud) David Walsh在这里有一个很好的去抖动实现。
// Returns a function, that, as long as it continues to be invoked, will not
// be triggered. The function will be called after it stops being called for
// N milliseconds. If `immediate` is passed, trigger the function on the
// leading edge, instead of the trailing.
function debounce(func, wait, immediate) {
var timeout;
return function() {
var context = this, args = arguments;
var later = function() {
timeout = null;
if (!immediate) func.apply(context, …Run Code Online (Sandbox Code Playgroud) Google在" 将analytics.js添加到您的网站 "指南中提供以下代码段:
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
Run Code Online (Sandbox Code Playgroud)
这段代码是否初始化了Google Analytics?怎么样?
typescript ×4
javascript ×3
asynchronous ×1
c# ×1
debouncing ×1
dom ×1
events ×1
inheritance ×1
json ×1
node.js ×1
oop ×1
php ×1
swift ×1
symfony1 ×1
transform ×1