我读了TypeScript 模块解析的工作原理.
我有以下存储库:ts-di.编译目录结构后如下:
??? dist
? ??? annotations.d.ts
? ??? annotations.js
? ??? index.d.ts
? ??? index.js
? ??? injector.d.ts
? ??? injector.js
? ??? profiler.d.ts
? ??? profiler.js
? ??? providers.d.ts
? ??? providers.js
? ??? util.d.ts
? ??? util.js
??? LICENSE
??? package.json
??? README.md
??? src
? ??? annotations.ts
? ??? index.ts
? ??? injector.ts
? ??? profiler.ts
? ??? providers.ts
? ??? util.ts
??? tsconfig.json
Run Code Online (Sandbox Code Playgroud)
在我的package.json中,我写道"main": "dist/index.js".
在Node.js中一切正常,但TypeScript:
import {Injector} from …Run Code Online (Sandbox Code Playgroud) 我<div [innerHTML]="body"></div>用来将未转义的HTML传递给我的模板,当我传递给body div属性时id,Angular throw:
警告:清理HTML会删除一些内容(请参阅http://g.co/ng/security#xss).警告:清理HTML会删除一些内容(请参阅http://g.co/ng/security#xss).警告:清理HTML会删除一些内容(请参阅http://g.co/ng/security#xss).
那为什么这么说呢?什么可能是危险id的div?可能这个bug?
我ngsw-config.json(摘自文档):
{
"index": "/index.html",
"assetGroups": [{
"name": "app",
"installMode": "prefetch",
"resources": {
"files": [
"/favicon.ico",
"/index.html"
],
"versionedFiles": [
"/*.bundle.css",
"/*.bundle.js",
"/*.chunk.js"
]
}
}, {
"name": "assets",
"installMode": "lazy",
"updateMode": "prefetch",
"resources": {
"files": [
"/assets/**"
]
}
}]
}
Run Code Online (Sandbox Code Playgroud)
在我的网站上有一个指向RSS源的链接,该链接/api/rss应该在新的浏览器选项卡中打开而不加载Angular应用程序.如何将其从请求重定向到的资源列表中排除index.html?
UPD:我试过但没有使用以下配置(请参阅参考资料!/api/rss):
{
"index": "/index.html",
"assetGroups": [{
"name": "app",
"installMode": "prefetch",
"patterns": ["!/api/rss"],
"resources": {
"files": [
"/favicon.ico",
"/index.html",
"!/api/rss"
],
"versionedFiles": [
"/*.bundle.css",
"/*.bundle.js",
"/*.chunk.js"
]
} …Run Code Online (Sandbox Code Playgroud) 以下代码在返回的类型方面是正确的,因为then始终返回promise数组.
Promise.resolve(['one', 'two'])
.then( arr =>
{
if( arr.indexOf('three') === -1 )
return Promise.reject( new Error('Where is three?') );
return Promise.resolve(arr);
})
.catch( err =>
{
console.log(err); // Error: where is three?
})
Run Code Online (Sandbox Code Playgroud)
TypeScript抛出错误:
类型参数'TResult'的类型参数不能从用法中推断出来.考虑明确指定类型参数.类型参数候选'void'不是有效的类型参数,因为它不是候选'string []'的超类型.
但实际上,then永远不会回归void.
我可以明确指定类型.then<Promise<any>>,但它更像是一种解决方法,而不是正确的解决方案.
怎么写这个吧?
我有以下代码:
interface First
{
propertyA: string;
}
// Here propertyA is optional
// Imagine that this interface came from external library.
interface Second
{
propertyA ?: string;
}
function fn(arg: First)
{
// ...
}
// I know that this object can be declared as type of First,
// but I really need set this as type of Second interface
let myVar: Second = {propertyA: 'some string'};
// I really need in this way to make the call.
fn(myVar); // …Run Code Online (Sandbox Code Playgroud) 我对这个问题有类似的问题:https://stackoverflow.com/a/2364223/1716560
我有两个分支:uk和uk-prod:
git checkout uk-prod
Already on 'uk-prod'
git diff --name-status uk-prod..uk
A pages/Advanced Types.md
A pages/Basic Types.md
A pages/Classes.md
Run Code Online (Sandbox Code Playgroud)
我想只得到文件pages/Advanced Types.md:
git checkout uk -- "page/Advanced Types.md"
Run Code Online (Sandbox Code Playgroud)
但是git throw:
error: pathspec 'page/Advanced Types.md' did not match any file(s) known to git.
Run Code Online (Sandbox Code Playgroud)
据我所知,它发生是因为git没有看到本地文件page/Advanced Types.md.是否?
我的 TypeScript v2.2。
我有这个班级工厂:
export class A { name: string; }
export function makeConstructor(name: string)
{
const newClass = class extends A { };
newClass.prototype.name = name;
return newClass;
}
Run Code Online (Sandbox Code Playgroud)
打字稿抛出错误:
导出函数的返回类型具有或正在使用私有名称“(匿名类)”。
我可以说这个工厂返回any隐藏错误,但我如何解释究竟返回了什么?
我试着写
makeConstructor<T extends A>(name: string): TmakeConstructor<T extends typeof A>(name: string): TmakeConstructor<T extends A['prototype']>(name: string): T['prototype']我的 TypeScript v2.2.1,我有对象列表my-module:
export const OneObj = { prop1: 'value1' }
export const TwoObj = { prop2: 'value2' }
Run Code Online (Sandbox Code Playgroud)
我想在另一个模块中创建新类型:
import * as importedObject from './my-module';
console.log(importedObject)
// { OneObj: { prop1: 'value1' }, TwoObj: { prop2: 'value2' } }}
type NewType = keyof importedObject;
// Error: Cannot find name 'importedObject'
Run Code Online (Sandbox Code Playgroud)
为什么 TypeScript 会抛出错误?
找不到名称“importedObject”
同时,我可以这样做:
type NewType = keyof { OneObj: { prop1: 'value1' }, TwoObj: { prop2: 'value2' } };
// NewType === ("OneObj" | "TwoObj")
Run Code Online (Sandbox Code Playgroud) 创建一个“顶级组件”,充当所有模块组件的根。将自定义 HttpBackend 提供程序添加到顶部组件的提供程序列表而不是模块的提供程序。回想一下,Angular 为每个组件实例创建一个子注入器,并使用组件自己的提供程序填充注入器。
当该组件的子组件请求 HttpBackend 服务时,Angular 会提供本地 HttpBackend 服务,而不是应用程序根注入器中提供的版本。无论其他模块对 HttpBackend 执行什么操作,子组件都会发出正确的 http 请求。
确保将模块组件创建为该模块顶部组件的子组件。
如果我们打开分层依赖注入器文档的源文件,我们可以看到ACarComponent,BCarComponent并创建,和CCarComponent的三个不同实例。CarServiceCarService2CarService3
但是,如果我也在模块级别上提供,如何CarService从父组件的 DI 中获取子组件呢?BCarComponentCarService
当我们说"实例"时,我们假设我们正在处理一个对象.为什么JavaScript的运算符在我们要求时instanceof返回,但是?为什么不呢?true(class A { }) instanceof Functiontypeof (class A { }) == "function"object
typescript ×5
angular ×3
javascript ×2
cookies ×1
es6-promise ×1
generics ×1
git ×1
git-checkout ×1
hierarchy ×1
node-modules ×1
node.js ×1
plugins ×1
restify ×1
security ×1
types ×1
warnings ×1