要在npm脚本中访问变量,您可以在以下内容中执行以下操作package.json:
"scripts": {
"preinstall": "echo ${npm_package_name}"
}
Run Code Online (Sandbox Code Playgroud)
问题是只能在Unix中使用,而不能在Windows中使用%npm_package_name%.
有没有办法让这个OS独立?在调用命令之前,如果npm可以执行这样的变量扩展,那将是很好的.
关于如何以递归方式将TypeScript的部分映射类型应用于接口的任何想法,同时不破坏任何具有数组返回类型的键?
以下方法还不够用:
interface User {
emailAddress: string;
verification: {
verified: boolean;
verificationCode: string;
}
activeApps: string[];
}
type PartialUser = Partial<User>; // does not affect properties of verification
type PartialUser2 = DeepPartial<User>; // breaks activeApps' array return type;
export type DeepPartial<T> = {
[ P in keyof T ]?: DeepPartial<T[ P ]>;
}
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
更新:接受的答案 - 现在更好,更一般的解决方案.
我找到了一个临时解决方法,涉及类型和两个映射类型的交集,如下所示.最显着的缺点是你必须提供属性覆盖来恢复被污染的密钥,具有数组返回类型的密钥.
例如
type PartialDeep<T> = {
[ P in keyof T ]?: PartialDeep<T[ P ]>;
}
type PartialRestoreArrays<K> = {
[ P in …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用react来重新创建我的current组件(用纯打字稿编写),但我找不到一种方法来为扩展另一个的组件提供额外的道具.
export interface DataTableProps {
columns: any[];
data: any[];
}
export class DataTable extends React.Component<DataTableProps, {}> {
render() {
// -- I can use this.props.columns and this.props.data --
}
}
export class AnimalTable extends DataTable {
render() {
// -- I would need to use a this.props.onClickFunction --
}
}
Run Code Online (Sandbox Code Playgroud)
我的问题是我需要给AnimalTable一些与DataTable无关的道具.我怎样才能做到这一点 ?
orderBy在我的输入框列表中应用后,如果我编辑任何字段,它立即开始排序,我松散焦点.我尝试挖掘角度代码并发现他们在orderBy的属性上应用了类似于$ watch的东西,因此每当值更改时,它会对列表进行排序.是否有任何方法可以在编辑时禁用orderBy?我不想让orderBy在编辑文本时对数据进行排序.任何帮助将不胜感激
注意:我想使用orderBy并且不需要任何替代方法,例如从任何控制器本身对列表进行排序.我只是希望orderBy在页面加载时对列表进行一次排序,然后保持相当.
我正在尝试使用TypeScript创建一个AngularJS指令.我的指令需要'ngModel',我也使用在我的指令中注入的自定义服务.我的主要问题是我的服务无法在我的链接功能中使用.
这是我想要实现的一个例子:
module app.directives {
export var directiveName: string = "theDirective";
angular.module("myApp").directive(directiveName,
(myFactory: app.services.MyFactory) =>
{
return new MyDirective(myFactory);
});
export interface IMyDirectiveScope extends ng.IScope {
ngModel: ng.INgModelController;
}
export class MyDirective implements ng.IDirective {
restrict = "A";
require = "ngModel";
scope = {
ngModel:'='
}
constructor(private myFactory: app.services.MyFactory) {
}
link(scope: IMyDirectiveScope , elem: JQuery, attributes: ng.IAttributes, ngModel: ng.INgModelController) {
//this is window here
elem.bind('blur', (evt: JQueryEventObject) => {
//keyword this is also window here, so yeah bummer indeed …Run Code Online (Sandbox Code Playgroud) 考虑以下C程序(test.c):
#include <stdio.h>
int main() {
printf("string out 1\n");
fprintf(stderr, "string err 1\n");
getchar();
printf("string out 2\n");
fprintf(stderr, "string err 2\n");
fclose(stdout);
}
Run Code Online (Sandbox Code Playgroud)
哪个应该打印一行到stdout,一行到stderr,然后等待用户输入,然后另一行到stdout,另一行到stderr.非常基本!在编译并在命令行上运行时,程序的输出完成(收到getchar()的用户输入):
$ ./test
string out 1
string err 1
string out 2
string err 2
Run Code Online (Sandbox Code Playgroud)
尝试使用带有以下代码的nodejs将此程序生成为子进程时:
var TEST_EXEC = './test';
var spawn = require('child_process').spawn;
var test = spawn(TEST_EXEC);
test.stdout.on('data', function (data) {
console.log('stdout: ' + data);
});
test.stderr.on('data', function (data) {
console.log('stderr: ' + data);
});
// Simulate entering data for getchar() after 1 second
setTimeout(function() { …Run Code Online (Sandbox Code Playgroud) 想要检查三星Galaxy上的网站,它在框中使用了什么浏览器,我可以在哪里模拟它 - 在线还是在OSX上?
我要问的原因是一些CSS属性不起作用,需要找到修复.
我正在使用Xamarin,我需要看起来像这样的东西:
public Colors = new object() {
Blue = Xamaring.Color.FromHex("FFFFFF"),
Red = Xamarin.Color.FromHex("F0F0F0")
}
Run Code Online (Sandbox Code Playgroud)
所以我以后可以这样做:
myObject.Colors.Blue // returns a Xamarin.Color object
Run Code Online (Sandbox Code Playgroud)
但是,当然,这不编译.显然,我需要为此创建一个完整的新类,我真的不想做,也不认为我应该这样做.在javascript中,我可以做这样的事情:
this.colors = { blue: Xamarin.Color.FromHex("..."), red: Xamarin... }
Run Code Online (Sandbox Code Playgroud)
C尖锐的东西可以帮我快速实现吗?谢谢
我的问题是我需要查询泛型类中属性的值.该属性标有属性.
请参阅以下代码:
var rowKeyProperty = EFUtil.GetClassPropertyForRowKey<T>();
var tenantKeyProperty = EFUtil.GetClassPropertyForTenantKey<T>();
var queryResult =
objContext.CreateObjectSet<T>().Single(l => (((int) tenantKeyProperty.GetValue(l, null)) == tenantKey) &&
(((int)rowKeyProperty.GetValue(l, null)) == KeyValue));
Run Code Online (Sandbox Code Playgroud)
rowKeyProperty和tenantKeyProperty的类型为System.Reflection.PropertyInfo.
我理解为什么我收到错误.当linq查询转换为SQL时,它无法理解property.GetValue.
但是,我对这里的工作感到非常难过.有没有人有任何想法如何实现这一目标?谢谢.
在状态中存储类是否被认为是不好的做法?我读过状态应该是容易序列化的对象和类打破了这个约定。
我正在创建一个 Web 应用程序,它使用 React/Redux 和一组支持模型来收集用户的信息。
例如,我有以下模型:
class Person {
constructor(params = {}) {
this.firstName = params.firstName || '';
this.lastName = params.lastName || '';
this.gender = params.gender || '';
this.dateOfBirth = params.dateOfBirth || '';
this.stateOfResidence = params.stateOfResidence || '';
this.email = params.email || '';
}
validateField(args) {
// remove for brevity
}
valid(args) {
// remove for brevity
}
}
Run Code Online (Sandbox Code Playgroud)
通过发出以下 actionCreator 将对象添加到存储中:
export function addPerson(args = {}) {
return (dispatch) => {
dispatch({
type: 'ADD_PERSON',
obj: new Person(args)
}); …Run Code Online (Sandbox Code Playgroud) typescript ×3
angularjs ×2
c# ×2
javascript ×2
node.js ×2
reactjs ×2
.net ×1
android ×1
browser ×1
collections ×1
emulation ×1
galaxy ×1
linq ×1
mapped-types ×1
npm ×1
object ×1
package.json ×1
partial ×1
recursion ×1
redux ×1
spawn ×1
state ×1
stdout ×1
unbuffered ×1