小编Roo*_*omy的帖子

docker-compose的context或workdir

我正在学习码头工人

我需要为docker镜像指定工作目录,我想这将是这样的:

version: '2'
services:
  test:
    build:
      context: ./dir
Run Code Online (Sandbox Code Playgroud)

现在我想让图像python:onbuild在上面运行./dir,但我不想在Dockerfile里面创建任何内容./dir.

docker-compose手册没有提到这一点.

可能吗?怎么做?

docker docker-compose

38
推荐指数
3
解决办法
5万
查看次数

TypeScript:找不到名称async/await

我正在使用typescript@next,我想编译我的代码es5,但每次我使用asyncawait关键字编译器错误与该消息:

Cannot find name 'await'.
Run Code Online (Sandbox Code Playgroud)

我的继承人库:dom,es2015,es2016,es2017.

代码示例:

let asyncFn = () => {
   return new Promise((resolve:Function)=>{resolve(2)})
}
// should log `2`
console.log(await asyncFn())
Run Code Online (Sandbox Code Playgroud)

这样的事情是可能的,即使typescript@2.0.x我已经尝试过,但无论如何我无法编译我的代码.

async-await typescript

19
推荐指数
1
解决办法
1万
查看次数

TypeScript ES动态`import()`

在使用新的TypeScript功能(即所谓的ES Dynamic Imports)时,我无法使用服务器端运行我的同构应用程序的代码ts-node.

使用webpack模块加载器时,似乎没有出现错误,该加载器以自己的方式转换代码并在浏览器中运行生成的文件.

我得到的错误:

case 0: return [4 /*yield*/, import("./component/main")];
                             ^^^^^^
SyntaxError: Unexpected token import
Run Code Online (Sandbox Code Playgroud)

通常TypeScript将import表达式转换为类似的东西:Promise.resolve(require("./component/main"))但我在那里看不到它.

如何解决?它有什么共同之处ts-node吗?或者有一个"polyfill" node.js

我的tsconfig.json档案:

{
  "compilerOptions": {
    "declaration": false,
    "emitDecoratorMetadata": true,
    "allowJs": false,
    "experimentalDecorators": true,
    "importHelpers": true,
    "inlineSourceMap": false,
    "inlineSources": false,
    "lib": [
      "DOM",
      "ES5",
      "ES6",
      "ES7"
    ],
    "listFiles": false,
    "module": "commonjs",
    "noEmitOnError": true,
    "noImplicitAny": true,
    "noImplicitReturns": true,
    "noImplicitThis": true,
    "preserveConstEnums": false,
    "pretty": false,
    "removeComments": false,
    "strict": true,
    "target": "es5"
  } …
Run Code Online (Sandbox Code Playgroud)

node.js typescript ts-node typescript2.4

7
推荐指数
1
解决办法
4261
查看次数

选择具有给定类型值的属性

我想要一个类型,它允许我只从对象中选择那些值扩展给定类型的属性,例如:

type PickOfValue<T, V extends T[keyof T]> = {
    [P in keyof (key-picking magic?)]: T[P];
};
Run Code Online (Sandbox Code Playgroud)

所以不知何故,我需要选择T其值是一种类型的键(属性) V(条件T[P] extends Vtrue),我找不到任何方法来解决这个问题,所以在这里询问是我最后的帮助手段。

结果示例:

PickOfValue<Response, () => Promise<any>>; // {json: () => Promise<any>, formData: () => Promise<FormData>, ...}
PickOfValue<{a: string | number, b: string, c: number, d: "", e: 0}, string | number>; // {a: string | number, b: string, c: number, d: "", e: 0}
Run Code Online (Sandbox Code Playgroud)

typescript

3
推荐指数
1
解决办法
767
查看次数

如何返回Http响应?

我想知道是否可以做以下事情:

我需要GET直接从http 请求返回响应,而不是返回Observable<Response>实例.

这个例子可能会澄清整个事情:

@Injectable()
export class ExampleService {
  constructor( @Inject(Http) protected http: Http) { }
  static model: { [uri: string]: any } = {}
  public get(uri: string): any {
    if (typeof ExampleService.model[uri] === 'undefined') {
      ExampleService.model[uri] = this.http.get(uri).map(response => response.json()) // additionally do some magic here, it is Observable<any> instance now
    }
    return ExampleService.model[uri]
  }
}
Run Code Online (Sandbox Code Playgroud)

总结:根据GünterZöchbauer的说法,上面的解决方案是不可能的,而不是我需要使用这样的东西:

  public get(uri: string): Observable<any> {
    return new Observable(observer => {
      if (!ExampleService.model[uri]) {
        let sub = …
Run Code Online (Sandbox Code Playgroud)

javascript rxjs typescript angular

1
推荐指数
1
解决办法
95
查看次数