我正在尝试为我的Web应用程序安装打字稿键入,但无法获得命令提示符以识别该typings命令。
typings install 引发以下错误:
'typings' is not recognized as an internal or external command,
operable program or batch file.
Run Code Online (Sandbox Code Playgroud)
当我运行时npm i typings -g,控制台会告诉我模块已安装。但是当我查看全局npm目录时,没有打字文件。
C:\gitdev\MyWebApp\src\main\webapp\myUI>npm i typings -g
C:\home\123456\AppData\Roaming\npm\typings -> C:\home\123456\AppData\Roaming\npm\node_modules\typings\dist\bin.js
C:\home\123456\AppData\Roaming\npm
`-- typings@2.1.1
Run Code Online (Sandbox Code Playgroud)
123456为了安全起见,我的用户名已被替换为。其他所有内容均逐字复制。
我没有管理员权限(我在工作计算机上)
where typings 还会引发错误(信息:找不到给定模式的文件。
npm -g对于grunt-cli效果很好
npm在我的PATH中 C:\Users\123456\AppData\Roaming\npm
我可能会误会,但是在操场上看打字稿时,我注意到它们将类的方法和对象变量包装在一起,感觉每次我调用一个新对象时,它可能会降低性能。
例如Class的Typescript游乐场输出
var FatObject = (function () {
function FatObject(thing) {
this.objectProperty = 'string';
this.anotherProp = thing;
}
FatObject.prototype.someMassivMethod = function () {
//many lines of code
//...
//...
//...
//.......................
};
return FatObject;
}());
var thing = 'example';
var objOne = new FatObject(thing);
var objTwo = new FatObject(thing);
var objThree = new FatObject(thing);
var objFour = new FatObject(thing);
Run Code Online (Sandbox Code Playgroud)
我觉得如果我编写大量方法,那么每次我从类中创建一个新对象时,我也会编译这些大量方法。
创建新对象时,无需在函数名称之外声明方法。
例如老方法:
function ThinObj(thing) {
this.anotherProp = thing;
this.objectProperty = 'string';
}
ThinObj.prototype.someMassivMethod = function() {
//many lines of code …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 .net core web api。我创建了一个静态方法来注册我的控制器,如下所示:
public static class RegistrationExtensions
{
public static void RegisterApplicationServices(this IServiceCollection services, IServiceProvider serviceProvider)
{
services.RegisterSingletons();
services.RegisterRequests();
services.RegisterTransient(serviceProvider);
}
public static void RegisterSingletons(this IServiceCollection services)
{
services.AddSingleton<Configuration>();
}
public static void RegisterRequests(this IServiceCollection services)
{
services.AddScoped<ISettingsService, SettingsService>();
}
public static void RegisterTransient(this IServiceCollection services, IServiceProvider serviceProvider)
{
var config = serviceProvider.GetService<Configuration>();
services.AddDbContext<InteractiveChoicesContext>(m => m.UseSqlServer(config.ConnectionString));
}
}
Run Code Online (Sandbox Code Playgroud)
如您所见,我想解析包含我的ConnectionString 的Configuration类,我将其传递给DbContext。请解决我尝试使用IServiceProvider的配置,该配置注入RegisterApplicationServices方法。
为了调用这个方法,我将Startup类的 …
c# entity-framework-core asp.net-core-mvc asp.net-core asp.net-core-webapi
假设我想创建一个字典,例如,汽车品牌到一个或多个模型。
似乎我可以在 ES6 中以两种不同的方式做到这一点。
1. 创建一个对象映射:
代码:
const makesAndModels = {
"mazda": [
{ name: "Miata" },
{ name: "626" }
],
"toyota": [
{ name: "Camry" }
],
...
};
Run Code Online (Sandbox Code Playgroud)
2. 创建一个 ES6 Map 实例:
代码:
const makes = {
mazda: { name: "Mazda" },
toyota: { name: "Toyota" }
};
const makesAndModels = new Map([
[makes.mazda, [
{ name: "Miata" },
{ name: "626" }
]],
[makes.toyota, [
{ name: "Camry" }
]],
...
]);
Run Code Online (Sandbox Code Playgroud)
上述两种方法之间的主要区别和优缺点是什么?
const { SchemaLink } = require('apollo-link-schema')
我已经尝试过const { SchemaLink } = import('apollo-link-schema'),但它不起作用。ESLint 仍然显示错误@typescript-eslint/explicit-function-return-type
如何在 TypeScript 中动态导入命名导出?
我有一个Interface find,它包含方法cal(); 类a1和a2实现接口.a1返回一个数字,而a2返回一个数字.如何定义单个界面来解决我的问题.
以下是有上述内容的片段.
interface Ifind {
cal() : string;
}
class a1 implements Ifind{
public cal():string{
return "10";
}
}
class a2 implements Ifind{
public cal(): number{
return 12;
}
}
class main{
private obj;
constructor() {
this.obj = new a1();
var p = this.obj.cal();
alert(p)
}
}
Run Code Online (Sandbox Code Playgroud)
所以在C#中,当我一直在创建模型类和延迟加载时,我会这样做:
public int? User_ID { get; set; }
public int? Dept_ID { get; set; }
Run Code Online (Sandbox Code Playgroud)
然后在课堂上再往下走一点,我会像我这样在虚拟中弹出:
public virtual User User {get; set;}
public virtual Department Dept {get; set;}
Run Code Online (Sandbox Code Playgroud)
我怎么在打字稿中这样做?像这样的东西?:
User_ID: number;
Dept_ID: number;
User: User;
Dept: Department;
Run Code Online (Sandbox Code Playgroud)
我不认为接口是我想要/需要的......但是再次受到保护似乎也不正确.有些东西告诉我,我在这里错过了一个明显的答案.
我在角度6应用程序中有这个Date值:
expires_at: Date;
Run Code Online (Sandbox Code Playgroud)
在Java getter中,我使用String来获取值:
private String expires_at;
Run Code Online (Sandbox Code Playgroud)
但是当我使用这段代码转换时:
从String到LocalDateTime
terminals.setExpires_at(LocalDateTime.parse(terminalDTO.getExpires_at()));
Run Code Online (Sandbox Code Playgroud)
从LocalDateTime到String:
terminalNewDTO.setExpires_at(DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(terminals.getExpires_at()));
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
create] due to exception [Text '2019-02-19T01:00:00.000Z' could not be parsed, unparsed text found at index 23]
20:55:43,494 INFO [stdout] (default task-1) java.time.format.DateTimeParseException: Text '2019-02-19T01:00:00.000Z' could not be parsed, unparsed text found at index 23
20:55:43,494 INFO [stdout] (default task-1) at java.base/java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:2049)
20:55:43,494 INFO [stdout] (default task-1) at java.base/java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1948)
20:55:43,495 INFO [stdout] (default task-1) at java.base/java.time.LocalDateTime.parse(LocalDateTime.java:492)
20:55:43,495 INFO [stdout] (default task-1) at java.base/java.time.LocalDateTime.parse(LocalDateTime.java:477)
20:55:43,496 INFO [stdout] (default …Run Code Online (Sandbox Code Playgroud) 使用定义函数的变量还是首先使用函数更好?此外,tree-shaking 有区别吗?
我有很多计算(静态)密集型帮助程序类,并且想知道最好的(内存/速度)是什么。
这是我想到的不同方法:
class MyClass {
readonly functionA = (v: string | number, maxDeep: number, curDeep: number = 0): string => {
if (curDeep < maxDeep) {
return this.functionA(v, maxDeep, curDeep + 1);
} else {
return "function A" + v;
}
}
static functionB(v: string | number, maxDeep: number, curDeep: number = 0): string {
if (curDeep < maxDeep) {
return MyClass.functionB(v, maxDeep, curDeep + 1);
} else {
return "function B" + v;
}
}
functionC(v: string …Run Code Online (Sandbox Code Playgroud)我有一个水果课:
export class Fruit {
constructor(public id: number, public name: string) {}
public changeName(_name: string): void {
console.log('changing name')
this.name = _name
}
}
Run Code Online (Sandbox Code Playgroud)
我像这样实现它:
import React from 'react'
import { Fruit } from '../classes/fruit'
const HomePage = () => {
let fruit = new Fruit(1, 'apple')
return (
<div>
{fruit.name} <----- I am expecting this to update on the DOM when i click the button *********
<button onClick={() => fruit.changeName('banana')}>
change the name
</button>
</div>
)
}
export default …Run Code Online (Sandbox Code Playgroud) javascript ×7
typescript ×6
c# ×2
oop ×2
angular ×1
asp.net-core ×1
class ×1
ecmascript-6 ×1
es6-class ×1
function ×1
generics ×1
java ×1
npm ×1
npm-install ×1
overriding ×1
prototype ×1
reactjs ×1
tree-shaking ×1