我正在使用vscode-deno扩展,尽管我打开了deno.enable,deno.lint并且deno.unstable在我的 vscode 设置中,它不会在保存时格式化我的代码,我认为这是预期的行为。
相反,我使用RunOnSave扩展来运行deno fmt文件保存,但我想知道是否有办法单独使用 Deno 扩展来做到这一点?
我的.vscode/settings.json:
{
"deno.enable": true,
"deno.lint": true,
"deno.unstable": true,
"emeraldwalk.runonsave": {
"commands": [
{
"match": "\\.ts$",
"cmd": "deno fmt ${file}"
}
]
}
}
Run Code Online (Sandbox Code Playgroud) 当我测试SOP时,我遇到这种情况,两个文档与我期望的域具有相同的关系,当我尝试获取位置时会引发错误。
重现该问题:
let opened = window.open("https://www.google.com")opened.location.toString(),它将返回正确的位置document.domain = "www.google.com"从第一个选项卡做opened.location.toString(),您将得到一个错误
Uncaught DOMException: Blocked a frame with origin "https://www.google.com" from accessing a cross-origin frame.
at <anonymous>:1:12
Run Code Online (Sandbox Code Playgroud)谁能解释这个奇怪的行为?
让我们从我最喜欢的 JavaScript 表达式开始:
[]==[] // false
Run Code Online (Sandbox Code Playgroud)
现在,让我们说一下React 文档关于跳过副作用的内容:
如果某些值在重新渲染之间没有改变,你可以告诉 React 跳过应用效果。为此,将数组作为可选的第二个参数传递给 useEffect:
Run Code Online (Sandbox Code Playgroud)useEffect(() => {/* only runs if 'count' changes */}, [count])
现在让我们考虑以下行为让我挠头的组件:
[]==[] // false
Run Code Online (Sandbox Code Playgroud)
useEffect(() => {/* only runs if 'count' changes */}, [count])
Run Code Online (Sandbox Code Playgroud)
添加“apple”时,这是在控制台中记录的内容:
// on first render
Fruit changed to
Fruits changed to
// after each keystroke of 'apple'
Fruit changed to a
Fruit changed to ap
Fruit changed to app
Fruit changed to appl
Fruit changed to apple
// ater clicking on 'add' …Run Code Online (Sandbox Code Playgroud) 如何编写可选类型的立即解构参数?
举个例子,我希望以下函数可以在不提供任何参数的情况下调用。
const foo = ({bar}: {bar?: boolean}) => {};
Run Code Online (Sandbox Code Playgroud)
就像现在一样,TypeScript 抱怨缺少一个参数。
此代码无法编译:
const nodeIsUseless = (node: unknown) =>
node !== null &&
typeof node === "object" &&
"type" in node &&
typeof node.type === "string" &&
node.type === "JSXText";
Run Code Online (Sandbox Code Playgroud)
因为在最后两行:
类型“对象”上不存在属性“类型”。(2339)
...我自己可以理解,但我不明白为什么"type" in node检查后, TS 推断node仍然是 typeobject而不是 type { type: unknown; [key: string]: unknown },这不会触发 error。
我正在使用 laravel mix,如果我正确解释这个问题,我似乎无法找到反应。
我的测试:
import React from "react";
import renderer from "react-test-renderer";
import AppLayout from "../AppLayout";
test("it renders", () => {
const component = renderer.create(
<AppLayout pageTitle={undefined}>App</AppLayout>
);
let tree = component.toJSON();
expect(tree).toMatchSnapshot();
});
Run Code Online (Sandbox Code Playgroud)
这是我的 package.json
{
"private": true,
"scripts": {
"dev": "npm run development",
"development": "node node_modules/cross-env/dist/bin/cross-env.js NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch": "npm run development -- --watch",
"watch-poll": "npm run watch -- --watch-poll",
"hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
"prod": "npm run production",
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js …Run Code Online (Sandbox Code Playgroud) 当我运行npm test它时输出:
mocha ./tests/ --recursive --reporter mocha-junit-reporter
Run Code Online (Sandbox Code Playgroud)
并且所有测试运行良好。但是当我尝试调用 mocha 时,./tests/flickr/mytest --reporter junit-reporter我得到了:
Unknown "reporter": junit-reporter
Run Code Online (Sandbox Code Playgroud)
如何正确传递?
我想知道刷新运行 Vue 应用程序的页面是否会触发 Vue 的.destroyed回调。
从我在包含这些简单生命周期回调的 Vue 应用程序中观察到的:
created() {
console.log(' created');
},
destroyed() {
console.log('destroyed')?
}
Run Code Online (Sandbox Code Playgroud)
仅'created'记录(不记录'destroyed')。如何检查.destroyed回调是否已执行?
我有以下类型声明:
type Root = { r: string };
type A = { a: string };
type B = { b: string };
type Main = Root & (A | B);
Run Code Online (Sandbox Code Playgroud)
由于Main等效于{r: string, a: string} | {r: string, b: string},因此有效:
const main: Main = {
r: 'r',
a: 'a'
}
Run Code Online (Sandbox Code Playgroud)
这里没有惊喜。但是,这会引发以下错误:
const func : (main: Main) => void = main => {
main.a
/* ^
* [TS2339]
* Property 'a' doesn't exist on type 'Main'.
* Property …Run Code Online (Sandbox Code Playgroud) 我有这个类型
type Cartesian = { kind: 'cartesian'; x: number; y: number; }
type Polar = { kind: 'polar'; angle: number; distance: number }
type Movement = { name: string } & (Cartesian | Polar);
Run Code Online (Sandbox Code Playgroud)
我可以这样使用
const move = (movement: Movement) => { /* whatever */ };
move({ name: 'top right', kind: 'cartesian', x: 10, y: 10 });
move({ name: 'left', kind: 'polar', angle: Math.PI, distance: 10 });
Run Code Online (Sandbox Code Playgroud)
但由于某种原因,我不能这样使用它
const unnamedMove = (unnamedMovement: Omit<Movement, 'name'>) => {
move({ name: 'default', ...unnamedMovement …Run Code Online (Sandbox Code Playgroud) javascript ×5
typescript ×4
reactjs ×2
deno ×1
deno-fmt ×1
dom ×1
jestjs ×1
laravel ×1
mocha.js ×1
npm ×1
react-hooks ×1
typeguards ×1
union-types ×1
vue.js ×1