当将编译器选项的以太module或target属性设置为 esnext(id 喜欢使用import("example")语句)时,es6 导入语句将停止为npm installed 库工作(本地模块仍然工作:例如"./test.ts")。
所以这import * as asd from "testmodule";抛出cannot find module 'testmodule'. 然而,省略这两个属性使它工作。这是为什么,我应该使用什么标准来保留import("example")和import * as asd from "testmodule";声明?
这是我的完整 tsconfig.json:
{
"compilerOptions": {
"outDir": "./dist/",
"module": "esnext",
"target": "esnext",
"allowJs": true,
"sourceMap": true
}
}
Run Code Online (Sandbox Code Playgroud) 给出以下js命令:
[].flat;
Run Code Online (Sandbox Code Playgroud)
在浏览器(chrome / firefox)中执行:返回 function
使用nodejs v10.13.0执行它:返回 undefined
现在,我想知道节点RTE中还没有其他什么方法,像全局对象这样的文档在哪里Array。
似乎与相同Array.prototype.flatMap。
我正在使用java 8.
我最近遇到过这个:
public class Test {
public static void main(String[] args) {
String ss = "" + (Test.<Integer>abc(2));
System.out.println(Test.<Integer>abc(2));
}
public static <T> T abc(T a) {
String s = "adsa";
return (T) s;
}
}
Run Code Online (Sandbox Code Playgroud)
这不会抛出java.lang.ClassCastException.这是为什么?
我一直在思考+和System.out.println打电话toString.但是当我尝试这样做时,它会按预期抛出异常.
String sss = (Test.<Integer>abc(2)).toString();
Run Code Online (Sandbox Code Playgroud) 我想浏览,tsify和babelify我的代码.Browserify和其他一个开发者工作,但他们在一起.Babel似乎被忽略了(甚至没有读过.babelrc).
我有以下gulp代码:
const gulp = require("gulp");
const browserify = require("browserify");
const source = require('vinyl-source-stream');
const tsify = require("tsify");
const babelify = require("babelify");
function build() {
var b = browserify({
basedir: '.',
debug: true,
cache: {},
entries: ['src/index.ts'],
packageCache: {}
});
return b
.plugin(tsify)
.transform(babelify)
.bundle()
.on("error", function (err) { console.log("Error: " + err.message); })
.pipe(source('build.js'))
.pipe(gulp.dest("build"));
}
gulp.task("build", build);
Run Code Online (Sandbox Code Playgroud)
有了这个babelrc
{
"presets": ["minify"]
}
Run Code Online (Sandbox Code Playgroud)
和那些依赖
"@babel/core": "^7.2.2",
"babel-preset-minify": "^0.5.0",
"babelify": "^10.0.0",
"browserify": "^16.2.3",
"gulp": "^4.0.0",
"tsify": "^4.0.1",
"typescript": "^3.2.2",
"vinyl-source-stream": …Run Code Online (Sandbox Code Playgroud) I have the type of a class like here as A_Type?
class A {
constructor(public a: string) {}
}
type A_Type = {new (a: string): A}
Run Code Online (Sandbox Code Playgroud)
And Id like to get the type of the instance of the A_Type constructor, so that I could type this function explicitly
class A {
constructor(public a: number) {}
}
// ** not working **
function f<W extends { new(a: number): A }>(e: W): instanceof W {
return new e(2)
}
let w …Run Code Online (Sandbox Code Playgroud) 有没有办法在webcompoenents上添加css:hover效果(不是来自父级)。
我有以下示例代码
window.customElements.define('a-b', class extends HTMLElement {
constructor() {
super();
this.attachShadow({mode: 'open'}).innerHTML = `
<style>
:host {
display: block;
height: 100px;
width: 100px;
background: red;
}
:host:hover {
background: blue;
}
:host::selection {
background: rgba(0, 0, 0, 0.15);
}
</style>
<slot></slot>
`;
}
}
Run Code Online (Sandbox Code Playgroud)
该:host::selection物业按预期工作。但是:host:hover似乎没有任何作用。
我知道有解决此问题的方法,例如:
div:hover在父样式表上应用效果但是我想知道我是否只是为了简化代码而错过了一些东西(因为这似乎不太复杂)。
据我所知,异步函数将其返回值隐式包装到承诺中。这确实适用于所有属性,除了 Promise 本身。
async function f() {
return new Promise((res) => {
setTimeout(() => {
res("Why am I being unwrapped")
}, 1000)
})
}
(async () => {
console.log(await f())
})()
Run Code Online (Sandbox Code Playgroud)
那些在退回之前会被拆开。所以这await f()实际上等待着两个嵌套的承诺。
请注意,这也适用于显式创建的 Promises (
Promise.resolve(new Promise(...)))
有没有好的办法避免这种情况呢?我真的很想有一个嵌套的 Promise,而不需要像这样的快速修复。
async function y() {
return {wrapped: new Promise((res) => {
setTimeout(() => {
res("Why am I being unwrapped")
}, 1000)
})}
}
(async () => {
console.log((await y()).wrapped)
})()
Run Code Online (Sandbox Code Playgroud)
javascript ×5
typescript ×3
node.js ×2
animation ×1
arrays ×1
async-await ×1
asynchronous ×1
babeljs ×1
browserify ×1
casting ×1
css ×1
generics ×1
gulp ×1
html ×1
java ×1
node-modules ×1
promise ×1
shadow-dom ×1
svg ×1