我有一个简短的字符串文字列表,我想在 GraphQl 定义中表示它们。我尝试使用枚举,但它不适用于字符串文字。
假设我有一些字符串文字列表:
export const DanceTypeList = [
"truffle-shuffle",
"stanky-leg",
"ghost-ride-the-whip",
] as const;
// equivalent to ("truffle-shuffle" | "stanky-leg" | "ghost-ride-the-whip")
export type DanceType = typeof DanceTypeList[number];
Run Code Online (Sandbox Code Playgroud)
我怎样才能利用这个并创建一个比 GraphQlString 更具描述性的 GraphQl 类型?理想情况下,它能够在交互式用户界面中自动建议。
如果您简单地添加一个标记,您将获得一个标准标记:
https://docs.mapbox.com/mapbox-gl-js/example/add-a-marker/
如果您使用 addLayer() ,似乎没有任何关于如何使用这些标准标记的描述:
https://docs.mapbox.com/mapbox-gl-js/style-spec/layers/#symbol
map.addLayer({
'id': 'POIs',
'type': 'symbol',
'source': 'POIs',
'layout': {
'icon-image': 'marker-15', // this is a custom image... I just want a default, normal marker
'icon-allow-overlap': true
}
});
Run Code Online (Sandbox Code Playgroud)
添加特殊符号确实很容易,但我只想要默认标记。 如何使用 addLayer() 执行此操作
我遇到了与上述问题几乎完全相同的问题,但原因不同。
重申这个问题:
我有一些 html 文件:
<style> #hat { color: red; } </style>
<script> var hat = "fez"; </script>
Run Code Online (Sandbox Code Playgroud)
我正在通过 vanilla ajax 调用检索:
var request = new XMLHttpRequest();
request.open('GET', target, true);
request.onload = function() {
if (request.status >= 200 && request.status < 400) {
// Success!
var response = request.responseText;
} else {
// We reached our target server, but it returned an error
}
};
request.onerror = function() {
// There was a connection error …
Run Code Online (Sandbox Code Playgroud) 我有一个控制器方法
// ... inside a controller class
@get('/error', {})
async error() {
throw new Error("This is the error text");
}
Run Code Online (Sandbox Code Playgroud)
我从此错误前端得到的响应是:
{“ error”:{“ statusCode”:500,“ message”:“内部服务器错误”}}
我想要的错误是:
{“ error”:{“ statusCode”:500,“ message”:“这是错误文本”}}
如何从Loopback 4中的控制器返回错误?
我正在尝试解决具有形式和功能的此问题。以下是该问题的两个示例,一个功能失调,但具有我想要达到的形式水平,另一个功能正常,但乏味。
const foo = "Spam";
const bar = () => "Ham";
const qux = (bool) => bool ? "Eggs" : "Beans";
// This is roughly the level of succintless I'd like to achieve
function genObjectPretty(request) {
return {
foo: request.foo && foo,
bar: request.bar && bar(),
qux: request.qux && qux(true),
}
}
console.log("BAD results, with SHORT code. (bar should not be included)")
console.log(genObjectPretty({foo: true, qux: true}));
// This is the working code which I'd like to make less verbose
function …
Run Code Online (Sandbox Code Playgroud)OpenApi 规范列出了一系列可以为其设置的字段和值。您可以在此处查看规格。
我想要一组定义这些规范的接口...我已经开始从头开始制作一个接口,到目前为止它看起来像这样:
// Totally incomplete
export interface IEndpointDocs {
path: string,
methods: {
get?: IMethodDocs,
post?: IMethodDocs
}
}
export interface IMethodDocs {
description?: string,
operationId?: string,
produces?: Array<
| "application/json"
| "application/xml"
| "text/xml"
| "text/html"
>,
parameters: IMethodParameterDocs[],
}
export interface IMethodParameterDocs {
name: string,
in: "query" | "body" | "path",
description?: string,
required?: boolean,
// really, barely started
type?: "array",
items: {
type: "string"
},
collectionFormat: "csv"
format: "int32"
};
Run Code Online (Sandbox Code Playgroud)
当然这已经完成了,那么我在哪里可以找到这些接口呢?
我有一些包含所有公共成员(本质上是一个结构)的类,我想存储它的数据:
class SomeClass {
public foo: string;
public bar: string;
public getFooBar() {
return this.foo + this.bar;
}
}
Run Code Online (Sandbox Code Playgroud)
作为存储检索的一部分,我希望有一个正确定义它的接口,例如:
interface ISomeClassData {
foo: string;
bar: string;
// notice there is no getFooBar()
}
const test: ISomeClassData = magic();
if ("getFooBar" in test === false) {
return "Success. This is an interface, and not a class";
}
Run Code Online (Sandbox Code Playgroud)
做这种事情的一种典型(但不适用)的方式如下:
interface ISomeClassData {
foo: string;
bar: string;
}
class SomeClass extends ISomeClassData {
// code omitted
}
Run Code Online (Sandbox Code Playgroud)
在我的场景中,类中公共属性的数量非常大,并且将某些内容添加到类中而不添加到接口中将非常非常容易。相反,我想做的是从类派生接口。
是否可以从 Typescript 中的类属性(省略方法)派生接口?
想象的例子: …
Stripe 文档对此确实含糊不清:
https://stripe.com/docs/billing/webhooks
续订前几天,您的网站会在 Webhook 端点收到一个发票.即将到来的事件。您可以侦听此事件以将额外的发票项目添加到订阅草稿发票中。
https://stripe.com/docs/billing/lifecycle
当订阅接近其续订日期时,将发送一个invoice.upcoming 事件。
invoice.upcoming
有谁知道网络钩子和实际发票之间大约有多少时间?“几天”可能是 2-5 天,具体取决于您询问的对象。
我有一个项目只打算与打字稿项目一起使用,并且希望代码检查转到打字稿代码的实际行(而不是定义文件)。
我似乎无法弄清楚如何为此设置 npm 项目。
我在 package.json 中正确设置了 main
{
// package.json details omitted
main: "./src/index.ts"
}
Run Code Online (Sandbox Code Playgroud)
经过检查,我已经验证了node_modules/my-project/src/index.ts
. 但是当我去import * from "my-project";
我得到错误:
找不到模块
这似乎表明不可能只有 npm 项目打字稿,但我想验证我不仅仅是犯了一个错误。
是否有可能只有打字稿的 npm 包?
typescript ×3
javascript ×2
node.js ×2
types ×2
ajax ×1
enums ×1
graphql ×1
html ×1
loopbackjs ×1
mapbox-gl-js ×1
npm ×1
openapi ×1
text ×1
webhooks ×1