我正在使用VS Code进行TypeScript/JavaScript开发.当我打开文件时,它会检查该文件是否有错误.问题是,如果我正在重构(就像我将一些共享代码移动到新位置或更改名称),它将不会显示我导致的错误,直到我打开带有问题的文件....所以,如果我想进行大量的重构,我必须打开每个文件,只是为了让它扫描文件中的错误.
如何让VS Code扫描整个项目的错误,而无需手动逐个打开每个文件?
当用户点击不同的元素时,我正在编写一个处理程序来对某个元素执行某些操作.
起初我有以下(这是使用Angular2,但我怀疑唯一不同的是如何onclick处理事件):
<span>
<input type="text" id="bioName">
</span>
<span class="icon-pencil" (click)="editField(bioName);"></span>
Run Code Online (Sandbox Code Playgroud)
......但这没效果.然后我找到了一个以不同方式识别输入字段的示例,这对我有用.它如下:
<span>
<input type="text" #bioName>
</span>
<span class="icon-pencil" (click)="editField(bioName);"></span>
Run Code Online (Sandbox Code Playgroud)
不幸的是我找不到任何解释这个的东西.使用HTML和Javascript搜索"hash"和"pound"会产生太多的结果,这些结果与主题领域中的内容无关.
那么#在这种情况下该怎么办?可以id设置事件处理程序时不能用来获得对DOM元素的引用?这叫什么,所以我可以google它并阅读相应的文档?
出于某种原因,我无法takeUntil在任何可观测量上使用该方法.
我的IDE(Visual Studio代码)在我编码时将它显示为一个有效的方法,它编译得很好(来自typescript),但是当我运行它时,我会看到takeUntil is not a function我的任何可观察对象.
我正在使用rxjs版本5.3.0.
我可以通过各种方式实现它,但这可能是最直接的:
let subject:BehaviorSubject<any> = new BehaviorSubject<any>({});
let unsubscribe: Subject<void> = new Subject<void>();
subject.takeUntil(unsubscribe);
Run Code Online (Sandbox Code Playgroud)
老实说,我找不到任何方法来实例化任何takeUntil不会导致错误的东西,但IDE从不抱怨并且打字机总是编译好 - 错误总是发生在浏览器中.
我有一个ngExpressEngine在 Angular 8 中使用 SSR 的大型应用程序。我运行了描述的所有升级过程,但我的server.ts文件没有正确迁移。特别是对provideModuleMap仍然的引用(Angular 9 不再支持它)。
请注意,我的路线都已正确更新,可以将新.then系统用于惰性路线。另请注意,它ng serve可以正常编译并正常工作。仅当我尝试从 express 运行 SSR 包时才会出现此问题。
我的问题可以与 Angular 8 中的这些代码行隔离开来:
// * NOTE :: leave this as require() since this file is built Dynamically
const {AppServerModuleNgFactory, LAZY_MODULE_MAP} = require('./dist/server/main');
// Our Universal express-engine (found @ https://github.com/angular/universal/tree/master/modules/express-engine)
app.engine('html', ngExpressEngine({
bootstrap: AppServerModuleNgFactory,
providers: [
provideModuleMap(LAZY_MODULE_MAP)
]
}));
Run Code Online (Sandbox Code Playgroud)
为了尝试让它在 Angular 9 中工作,我删除了对 的调用provideModuleMap(LAZY_MODULE_MAP)并传入了LAZY_MODULE_MAP,但这不起作用,因为它似乎LAZY_MODULE_MAP不再生成了。
...因此,随着我对 Angular 9 的更改,我从尝试运行只能运行客户端的服务器端的事情中得到了您期望的典型错误。即ReferenceError: window …
migration express server-side-rendering angular-universal angular
不幸的是,重现这一点的总代码将是广泛的,所以我希望我的问题很明显,我可以很容易地提供.如果需要,我会发布更完整的解决方案.
首先,我定义了一个接口:
export interface ITest {
myDate: Date;
}
Run Code Online (Sandbox Code Playgroud)
然后我创建一个这样的数组用于测试:
export const TEST: ITest[]=[{myDate: new Date(1995, 8, 1)}]
Run Code Online (Sandbox Code Playgroud)
我使用Angular2中的一个服务来暴露这些服务,该服务正在攻击InMemoryDbService angular2-in-memory-web-api.我调用它并获取数组的代码如下:
get(): Promise<ITest[]>{
return this.http.get(this.testUrl)
.toPromise()
.then(response => response.json().data as ITest[])
.catch(this.handleError);
}
Run Code Online (Sandbox Code Playgroud)
...然后我把它带到我的组件中:
this.testService.get().then(tests => {
this.tests = tests;
console.log("Date Type:"+typeof(this.tests[0].myDate));
});
Run Code Online (Sandbox Code Playgroud)
这一切都很好,但问题是console.log显示的结果如下:
Date Type:string
Run Code Online (Sandbox Code Playgroud)
其中的数据是正确的,因为我的日期所持有的字符串是1995-09-01T07:00:00.000Z,但主要问题是 - 它不是Date一个string!在VS Code中,我甚至可以获得方法的代码完成,toDateString但是当我执行它们时,我(当然)得到了toDateString is not a function.
我很确定问题正在发生response => response.json().data as ITest[],但为什么不将日期数据转换为实际Date?我做错了,我明白了.我应该如何处理这个问题,以便我可以让我的对象获得我期望的类型?
我只是不能让类按钮align-right在中间垂直对齐.
HTML:
<div class="panel-footer">
<span style="width:100%;" class="header-footer-item">
<button class="align-right" type="button">Save</button>
</span>
</div>
Run Code Online (Sandbox Code Playgroud)
CSS:
.panel-footer {
height: 70px;
vertical-align: middle;
border: solid;
}
.header-footer-item {
display: inline-block;
line-height: 70px;
border: solid red;
}
.align-right {
float: right;
}
.align-middle {
vertical-align: middle;
}
Run Code Online (Sandbox Code Playgroud)
这是jsfiddle:https://jsfiddle.net/d1vrqkn9/2/
如果我float:right从按钮中移除它,它可以工作,但我希望它在右边.
如果我改变header-footer-item从inline-block到inline那么浮动按钮呈现其包含的元素,我认为是对上述规则:(在接受的答案#4这里如何垂直方向的中间对齐浮动无名高地的要素是什么?) -尽管父元素是然后在中间垂直对齐.
我已根据CSS添加行高度垂直对齐不适用于浮点数
最大的问题是 - 我该如何解决?我也有兴趣知道为什么使子元素(按钮)向右浮动使得父元素(span)不再在包含div中垂直对齐(但仅当它inline-block不是时inline)....最后,不是'违反规则'(https://www.w3.org/TR/CSS21/visuren.html#float-rules,#4),浮动箱的外部顶部要高一些比其包含块的顶部?......显然是这样header-footer-item的inline.
有很多关于垂直调整事物的问题,你认为他们会用"认真地,垂直地对齐这个东西 - 无论什么,没有抱怨,只是这样做: …
我想使用正确的错误处理来创建一个类型化的异步函数.
我可以这样定义一个:
export async function doSomething(userId:string) : Promise<ISomething | void> {
let somthing: ISomething = {};
try {
something.user = await UserDocument.findById(userId);
something.pet = await PetDocument.findOne({ownerId:userId});
return Promise.resolve(something);
} catch (err){
console.log("I would do some stuff here but I also want to have the caller get the error.");
return Promise.reject(err);
}
}
Run Code Online (Sandbox Code Playgroud)
...这似乎有效,但(由于明确的原因),如果我尝试将结果分配给ISomething对象,我会得到错误Type 'void | ISomething' is not assignable to type 'ISomething'.
let iSomething:ISomething;
iSomething = await doSomething('12'); //this give me the error
Run Code Online (Sandbox Code Playgroud)
我知道那是为什么.我的问题是,在这样的情况下,我应该使用什么模式进行错误处理?请注意,如果返回类型是,Promise<IProfile>那么我得到该 …
我可以在右侧创建一个带箭头的按钮,如下所示:
.next-button {
font-family: 'Source Sans Pro', Arial, Helvetica, sans-serif;
text-decoration: none;
color: #fff;
text-align: center;
border: none;
background-color: #2399e5;
display: inline-block;
height: 36px;
line-height: 36px;
padding: 0 1rem;
}
.next-point{
vertical-align: top;
width: 0;
height: 0;
display: inline-block;
border-top: 18px solid transparent;
border-bottom: 18px solid transparent;
border-left: 18px solid #2399e5;
border-right: 18px solid transparent;
}Run Code Online (Sandbox Code Playgroud)
<div>
<button class="next-button" type="button">Next</button><div class="next-point"></div>
</div>Run Code Online (Sandbox Code Playgroud)
...但是如果我尝试使用::之后它就会失效.这是我尝试过的方式:
.next-button {
font-family: 'Source Sans Pro', Arial, Helvetica, sans-serif;
text-decoration: none;
color: #fff;
text-align: center;
border: none; …Run Code Online (Sandbox Code Playgroud)我最近更新了npm到v5.0.1(从最后一个版本的4),它一般都是灾难性的.
无论如何,我已经陷入了困境.我尝试运行的任何node.js应用程序都完成了'npm install',但是在启动输出时:
module.js:471
throw err;
^
Error: Cannot find module 'fs.realpath'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/home/user/back/node_modules/glob/glob.js:44:10)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
Run Code Online (Sandbox Code Playgroud)
请注意,相同的应用程序将在macOs上正常运行,但在Ubuntu 16.04.2 LTS上它会出现上述错误.
我删除了两台机器上的node_modules目录并重新运行,macOs工作正常,Ubuntu失败.
node -v: v6.10.3
Run Code Online (Sandbox Code Playgroud)
......对于两台机器.
npm -v: 5.0.1
Run Code Online (Sandbox Code Playgroud)
它还建议我查看log(/home/user/.npm/_logs/2017-06-02T23_19_59_859Z-debug.log),但它提供的信息更少.这是在那里报告的错误:
13 info lifecycle back@0.0.1~start: Failed to exec start script
14 verbose stack Error: back@0.0.1 start: `tsc …Run Code Online (Sandbox Code Playgroud) 我有两个 Mongoose 查询,并决定最好.lean()在它们上使用。
对于返回单个文档的文档,它似乎工作正常:
let something:Something;
SomethingDocument.findOne({_id:theId}).lean().then( (res) => { something = res;});
Run Code Online (Sandbox Code Playgroud)
问题是当我尝试将它与返回多个结果的查询一起使用时:
let somethings:Something[];
SomethingDocument.find({color:'blue'}).lean().then( (res) => { somethings = res;});
Run Code Online (Sandbox Code Playgroud)
第二个调用给出了错误:
Type 'Object' is not assignable to type 'Something[]'.
The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead?
Property 'length' is missing in type 'Object'.
Run Code Online (Sandbox Code Playgroud)
如果我尝试进行类型转换,它只会抱怨“对象”类型中缺少“长度”属性。
lean当我期望一系列结果时如何使用?
...请注意,如果我只是省略lean它所有的作品。