我在jsdoc 3.4.0中使用es2015模块语法有两个小问题。
1)示例代码:
/** @module */
/** Example for a local function */
function localFUnction() {}
/** Example for an exported function */
function publicFunction() {
localFUnction();
}
export default {
publicFunction
};
Run Code Online (Sandbox Code Playgroud)
结果是:
Module: module/module
Methods
(inner) localFUnction()
Example for a local function
(inner) publicFunction()
Example for an exported function
Run Code Online (Sandbox Code Playgroud)
并且不承认函数 publicFunction 被导出并将两个函数标识为内部函数。
2)示例代码:
/** @module */
/** Example for a local function */
function localFUnction() {}
/** Example for an exported function */
export function publicFunction() {
localFUnction(); …Run Code Online (Sandbox Code Playgroud) 我目前正在评估zod在我的应用程序中的使用,并且在必须解析可以包含可选键的对象时遇到一个小问题。我使用 .passthrough 允许键保留在对象中,但希望自定义验证键或至少确保键名称和类型有效。.catchall 只允许指定所有可选键的类型,但我需要自定义验证每个可选键。
import {z} from 'zod';
// mandatory user information
const user = z.object({
id: z.number(),
name: z.string(),
});
// additional keys like:
// string: key in the format /^add_\d{3}_s$/
// number: key in the format /^add_\d{3}_n$/
add_001_s: z.string()
add_002_s: z.string()
add_003_n: z.number()
add_004_n: z.number()
Run Code Online (Sandbox Code Playgroud) 切换到流量0.54.0后,以下代码片段:
function runKarmaTest() {
const KARMA_CONFIG = {};
return new Promise(function (resolve, reject) {
new karma.Server(KARMA_CONFIG, function (exitCode) {
if (exitCode === 0) {
resolve();
} else {
reject(exitCode);
}
}).start();
});
}
Run Code Online (Sandbox Code Playgroud)
报告以下错误:
Error: scripts/runKarma.js:76
v----------------------------------------
76: return new Promise(function (resolve, reject) {
77: new karma.Server(KARMA_CONFIG, function (exitCode) {
78: if (exitCode === 0) {
...:
84: });
-^ type parameter `R` of constructor call. Missing annotation
Run Code Online (Sandbox Code Playgroud)
在线return new Promise(function (resolve, reject) {,我似乎无法弄清楚什么是错的?
当尝试从webpack 3迁移到4时,一些入口点生成的代码实际上不执行页面的"主"模块.
以下示例显示了将使用两个脚本标记加载的生成代码的关键部分.一个用于vendors.js和一个用于附加条目las_dlg_projectstatus.js.
应该执行的实际代码是在D:\MyDev\ljs_app\periscope_webpack4\build\src\modules\las_dlg_projectstatus\index.js加载具有id的模块时加载,86但是在加载页面时都不会加载/执行.
任何帮助非常感谢!
/******/ (function(modules) { // webpackBootstrap
/******/ // install a JSONP callback for chunk loading
/******/ function webpackJsonpCallback(data) {
/******/ var chunkIds = data[0];
/******/ var moreModules = data[1];
/******/ var executeModules = data[2];
/******/ // add "moreModules" to the modules object,
/******/ // then flag all "chunkIds" as loaded and fire callback
/******/ var moduleId, chunkId, i = 0, resolves = [];
/******/ for(;i < chunkIds.length; i++) …Run Code Online (Sandbox Code Playgroud) 我确信对于这种典型模式有一个优雅的解决方案,但我很难理解如何以类型保存的方式正确地增量创建对象。基本上我只想通过最初创建一个空对象然后添加所需的属性来创建一个具有预定义类型的对象。(我确实知道立即创建它不会导致此问题,但我的用例需要增量创建)
以下示例显示了我一直在尝试的选项以及每种方法的问题:
type myType = {
foo: string,
bar: number,
};
// has errors
function createA(): myType {
const o = {};
o.foo = 'foo'; // Error: Property 'foo' does not exist on type '{}'
o.bar = 0; // Error: Property 'bar' does not exist on type '{}'
return o; // Error: Type '{}' is missing the following properties from type 'myType': foo, bar
}
// has errors
function createB(): myType {
const o: myType = {}; // Type '{}' …Run Code Online (Sandbox Code Playgroud) 在这个简单的Babel(6.1.18)示例babel --presets es2015 test.js转换中:
'use strict'; // enable strict mode
(function () {
const A = 3;
}());
Run Code Online (Sandbox Code Playgroud)
至
'use strict' // enable strict mode
;
(function () {
var A = 3;
})();
Run Code Online (Sandbox Code Playgroud)
这主要是出于好奇,但我有兴趣更好地理解为什么: - 第一行中分号的位置已被移到一个单独的行 - 生命的语法已从更改(function () {}());为(function () {})();
JavaScript的selenium webdriver绑定允许通过组合两个等待命令来等待元素可见,如下例所示:
const timeout = 1000;
const locator = webdriver.By.id('test');
driver.wait(webdriver.until.elementLocated(locator, timeout).then(function() {
that.findElement(locator).then(function(element) {
driver.wait(webdriver.until.elementIsVisible(element), timeout).then(function() {
// element is visible!
});
});
});
Run Code Online (Sandbox Code Playgroud)
当我们需要等待一组元素一起可见时,是否有更简单的方法来完成此操作以及如何完成此操作?
我一直在使用flowjs,大多数错误信息都很清楚,但现在我有这样的事情:
src/framework/uitable/show.js:0
inconsistent use of library definitions
46: columns: Array<UiTableConfigColumnType>
^^^^^^^^^^^^^^^^^^^^^^^ object type. This type is incompatible with. See lib: src/framework/uitable/uitable.js.flow:46
52: type UiTableDataColsType = Array<string>;
^^^^^^ string. See lib: src/framework/uitable/uitable.js.flow:52
src/framework/uitable/show.js:0
inconsistent use of library definitions
52: type UiTableDataColsType = Array<string>;
^^^^^^ string. This type is incompatible with. See lib: src/framework/uitable/uitable.js.flow:52
46: columns: Array<UiTableConfigColumnType>
^^^^^^^^^^^^^^^^^^^^^^^ object type. See lib: src/framework/uitable/uitable.js.flow:46
Run Code Online (Sandbox Code Playgroud)
并且不知道该寻找什么.
定义中的类型似乎没问题,它们彼此无关,源指向第0行.
我以前从未见过这个错误,我不希望有任何帮助来追踪这个错误的实际来源.
我只是需要一些帮助来理解错误本身的含义以及为什么flowjs src/framework/uitable/show.js:0在第0行报告错误.
我正在寻找为 SPA 设置页面布局的最佳方法,该 SPA 由AppBar顶部的静态标题 ( ) 和标题下方的动态页面内容组成。页面内容ScreenSizePage有时(但不总是)的高度应该与屏幕的剩余高度完全匹配。换句话说:只有在 Material-UI 应用程序中使divin的高度ScreenSizePage完全适合剩余屏幕高度的最佳方法是什么?
索引.tsx:
import React from 'react';
import ReactDOM from 'react-dom';
import CssBaseline from '@material-ui/core/CssBaseline';
import {ThemeProvider} from '@material-ui/styles';
import {BrowserRouter} from 'react-router-dom';
import App from './App';
import theme from './theme';
ReactDOM.render(
<ThemeProvider theme={theme}>
<CssBaseline />
<BrowserRouter>
<App />
</BrowserRouter>
</ThemeProvider>,
document.querySelector('#root'),
);
Run Code Online (Sandbox Code Playgroud)
应用程序.tsx:
import React from 'react';
import {Route, Switch} from 'react-router-dom';
import AppBar from './AppBar';
import HomePage from './pages/HomePage';
import {ScreenSizePage} from …Run Code Online (Sandbox Code Playgroud) 以下代码片段报告了Type 'string' is not assignable to type 'never'.(2322)该行中的错误obj[prop] = value,我很难理解为什么?
interface fooType {
s: string,
n: number,
}
function bar(value: string, obj: fooType, prop: keyof fooType) {
if (typeof value === 'string') {
obj[prop] = value;
}
}
const foo = {s: '', n: 0};
bar('s', foo, 's');
console.log(foo);
Run Code Online (Sandbox Code Playgroud) javascript ×5
typescript ×3
ecmascript-6 ×2
flowtype ×2
node.js ×2
babeljs ×1
jsdoc ×1
material-ui ×1
reactjs ×1
selenium ×1
webdriver ×1
webpack ×1
zod ×1