如何定义导入的 json 的类型?例如
{
"things": "foo"
}
Run Code Online (Sandbox Code Playgroud)
interface Data {
things: String,
another?: String
}
Run Code Online (Sandbox Code Playgroud)
import data from './data.json' // Should have type Data
console.log(data.things)
console.log(data.another) // Should be allowed but undefined
Run Code Online (Sandbox Code Playgroud)
该resolveJsonModule
选项将自动为导入的 JSON 生成类型,但它是不完整的,因为 JSON 可能不包含数据的所有可能字段。
我自己如何定义类型?
我正在尝试以编程方式创建一个ShapeDrawable,但以下代码不显示任何内容.
ImageView image = new ImageView (context);
image.setLayoutParams (new LayoutParams (200, 200));
ShapeDrawable badge = new ShapeDrawable (new OvalShape());
badge.setBounds (0, 0, 200, 200);
badge.getPaint().setColor(Color.RED);
ImageView image = new ImageView (context);
image.setImageDrawable (badge);
addView (image);
Run Code Online (Sandbox Code Playgroud)
我可以使用xml.
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<size
android:width="200px"
android:height="200px" />
<solid
android:color="#F00" />
</shape>
ImageView image = new ImageView (context);
image.setLayoutParams (new LayoutParams (200, 200));
image.setImageResource (R.drawable.badge);
addView (image);
Run Code Online (Sandbox Code Playgroud)
但我想以编程方式创建它.xml工作得很好所以问题不能用于ImageView,它必须在创建ShapeDrawable.
我正在构建一个使用协议缓冲区的 flutter 应用程序,我想.proto
在构建过程中编译该文件。如何在 flutter 构建的 dart 编译之前运行自定义 shell 命令?
当文档加载时,我需要在创建具有类"nav"的元素时收到通知.谷歌搜索我发现MutationObservers并认为他们将是完美的,但我似乎无法让它工作.
// ==UserScript==
// @name ii-shortcuts
// @namespace https://github.com/RedHatter
// @include *
// @version 1
// @run-at document-start
// ==/UserScript==
var observer = new MutationObserver(function(mutations)
{
mutations.forEach(function(mutation)
{
if (mutation.target.getAttribute('class') == 'nav')
GM_log('nav creation');
});
});
observer.observe(document, {subtree: true, attributes: true, attributeFilter: ['class']});
Run Code Online (Sandbox Code Playgroud)
我也试过了.
// ==UserScript==
// @name ii-shortcuts
// @namespace https://github.com/RedHatter
// @include *
// @version 1
// @run-at document-start
// ==/UserScript==
var observer = new MutationObserver(function(mutations)
{
mutations.forEach(function(mutation)
{
if (mutation.addedNodes[0].getAttribute('class') == 'nav')
GM_log('nav creation');
});
});
observer.observe(document, …
Run Code Online (Sandbox Code Playgroud) 我使用下面的代码绘制到位图/画布的视图.
Bitmap bitmap = Bitmap.createBitmap(
viewGroup.getWidth (), viewGroup.getHeight (), Bitmap.Config.ARGB_8888);
viewGroup.draw(new Canvas(bitmap));
Run Code Online (Sandbox Code Playgroud)
它工作得很好,有一个小问题:它不会绘制高程阴影.我假设阴影不是在draw方法中绘制的.那么他们在哪里绘制,我怎样才能将它们转移到我的画布上?
我正在尝试在JavaScript中创建一个函数,给定一个字符串将返回一个字母的所有可能组合的数组,每个字母最多使用一次,从最短的开始.例如,对于字符串ABC,它将返回:
A
B
C
AB
AC
ABC
Run Code Online (Sandbox Code Playgroud)
我可以像这样使用循环:
for(i=0; i<string.length; i++) {
//add string[i]
}
for(i=0; i<string.length; i++) {
for(a=i; a<string.length; a++) {
//add string[i]+string[a]
}
}
for(i=0; i<string.length; i++) {
for(a=i; a<string.length; a++) {
for(b=a; b<string.length; b++) {
//add string[i]+string[a]+string[b]
}
}
}
Run Code Online (Sandbox Code Playgroud)
但我不知道字符串的长度,所以不知道要使用多少循环.
有任何想法吗?
编辑:我不是要求排列,abc和acb不应该都返回.此外,阵列中最短的第一个也很重要.
这不是功课.这是一个解决"熄灯"型游戏的程序.
我正在尝试使用CloudFormation为API网关定义自定义域(实际上是子域)。根据所有文档,我已经能够找到以下内容,但是在部署它时,我得到Invalid domain name identifier specified
了BasePathMapping
aws cloudformation deploy --template-file packaged-prompt.yaml --capabilities CAPABILITY_IAM --stack-name prompt-stack
Run Code Online (Sandbox Code Playgroud)
提示
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
...
Certificate:
Type: 'AWS::CertificateManager::Certificate'
Properties:
DomainName: example.mydomain.com
DomainName:
Type: 'AWS::ApiGateway::DomainName'
Properties:
CertificateArn: !Ref Certificate
DomainName: example.mydomain.com
Mapping:
Type: 'AWS::ApiGateway::BasePathMapping'
Properties:
DomainName: !Ref DomainName
RestApiId: !Ref Api
Api:
Type: AWS::Serverless::Api
Properties:
StageName: prod
DefinitionBody:
swagger: 2.0
info:
title:
Ref: AWS::StackName
paths:
....
Run Code Online (Sandbox Code Playgroud) 我有一组相对于复合材料的x/y坐标,如何找到那些coords落入的小部件?
我想使用 JQuery 将 unicode 放在 data-content 属性中,以便将其用于伪元素内容,但我找不到正确的格式。你如何显示unicode?休耕只是显示▼
。
a::after
{
content: attr(data-content);
}
Run Code Online (Sandbox Code Playgroud)
<a href="...">...</a>
Run Code Online (Sandbox Code Playgroud)
$("a").attr ("data-content", "▼");
Run Code Online (Sandbox Code Playgroud) 使用Webpack和Vue编译项目后,当我打开一个使用Vue组件的页面时,我得到:
[Vue warn]: Failed to mount component: template or render function not defined.
并代替Vue渲染的组件
<-- function (a, b, c, d) { return createElement(vm, a, b, c, d, true); } -->
Run Code Online (Sandbox Code Playgroud)
为什么会发生这种错误?
注意:我为此问题创建了一个MCVE.使用的确切Webpack配置是:
module.exports = {
entry: __dirname + '/display.js',
output: {
filename: 'bundle.js'
},
module: {
rules: [ { test: /\.vue$/, loader: 'vue-loader' } ]
}
}
Run Code Online (Sandbox Code Playgroud) 我见过一些加载器查询,require('-!some-loader!file.ext')
但无法-!
在文档中找到任何参考。我还看到过一些以!!
. 它们的含义是什么?它们记录在哪里?
如何获得k到h范围内的随机数,以使数字与h越接近,它出现的可能性就越小?
我需要20到1980年之间的数字。
我正在尝试使用,rejectionhandled
但无法启动。下面的代码应该基于我能找到的所有文档工作。我注册了一个监听器,rejectionhandled
然后拒绝一个承诺并抓住它。在启用了“测试”标志的 chrome 和 firefox 中,记录但未“拒绝”。我错过了什么?
window.addEventListener("rejectionhandled", e => console.log("rejected"), false);
new Promise((resolve, reject) => setTimeout(reject, 1000)).catch(err => console.error("testing"))
Run Code Online (Sandbox Code Playgroud) javascript ×3
android ×2
java ×2
webpack ×2
combinations ×1
composite ×1
coordinates ×1
css ×1
dart ×1
drawable ×1
flutter ×1
greasemonkey ×1
jquery ×1
promise ×1
random ×1
swt ×1
typescript ×1
unicode ×1
vue.js ×1