[英]TSLint object-literal-sort-keys is sorted alphabetically but error persists
TSLint is giveing me the warning The key 'allowedHeaders' is not sorted alphabetically (object-literal-sort-keys)tslint(1)
to me this is alphabetically sorted yet tslint insists there is an error. TSLint向我发出警告
The key 'allowedHeaders' is not sorted alphabetically (object-literal-sort-keys)tslint(1)
对我来说是按字母顺序排序的,但tslint坚持存在错误。
I also dont know how to define the callback any correctly. 我也不知道如何正确定义回调。
What am I missing? 我想念什么?
// Configure CORS
const corsOptions = {
origin: (origin: string, callback: any) => {
if (process.env.CORS_WHITELIST && process.env.CORS_WHITELIST.indexOf(origin) !== -1) callback(null, true);
else callback('Not allowed by CORS');
},
allowedHeaders: ['Accept', 'Authorization', 'Content-Length', 'Content-Type', 'X-Requested-With'],
methods: ['DELETE', 'GET', 'OPTIONS', 'POST', 'PUT'], optionsSuccessStatus: 200,
};
It's about the keys of the literal corsOptions
I think. 我想的是关于字面
corsOptions
的键的。 The key option
should be placed at the end. 关键
option
应放在最后。
It's not about string values inside of allowedHeader
, but about properties on corsOptions
. 这不是内部的字符串值
allowedHeader
,但有关性corsOptions
。 Regarding callback function, possible definition is (string, boolean?) => any
. 关于回调函数,可能的定义是
(string, boolean?) => any
。
Here is the type with both corrections: 这是经过两种修正的类型:
const corsOptions = {
allowedHeaders: ['Accept', 'Authorization', 'Content-Length', 'Content-Type', 'X-Requested-With'],
methods: ['DELETE', 'GET', 'OPTIONS', 'POST', 'PUT'], optionsSuccessStatus: 200,
origin: (origin: string, callback: (error: string, allowed?: boolean) => void) => {
if (process.env.CORS_WHITELIST && process.env.CORS_WHITELIST.indexOf(origin) !== -1) callback(null, true);
else callback('Not allowed by CORS');
}
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.