本文整理汇总了TypeScript中@ember/utils.isNone函数的典型用法代码示例。如果您正苦于以下问题:TypeScript isNone函数的具体用法?TypeScript isNone怎么用?TypeScript isNone使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了isNone函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: testIsNoneType
function testIsNoneType() {
const maybeUndefined: string | undefined = 'not actually undefined';
if (utils.isNone(maybeUndefined)) {
return;
}
const anotherString = maybeUndefined + 'another string';
utils.isNone(); // $ExpectType boolean
}
示例2: getHeader
/**
* Do a case-insensitive lookup of an HTTP header
*
* @function getHeader
* @private
*/
export default function getHeader(
headers: Headers | undefined,
name: string | undefined
): string | undefined | null {
if (isNone(headers) || isNone(name)) {
return undefined;
}
const matchedKey = A(Object.keys(headers)).find(key => {
return key.toLowerCase() === name.toLowerCase();
});
return matchedKey ? headers[matchedKey] : undefined;
}
示例3: updateData
updateData(data, initial) {
let recordDatas: RelationshipRecordData[] | undefined;
if (isNone(data)) {
recordDatas = undefined;
} else {
recordDatas = new Array(data.length);
for (let i = 0; i < data.length; i++) {
recordDatas[i] = this.recordData.storeWrapper.recordDataFor(data[i].type, data[i].id);
}
}
if (initial) {
this.setInitialRecordDatas(recordDatas);
} else {
this.updateRecordDatasFromAdapter(recordDatas);
}
}
示例4: isNone
(function() {
/** isNone */
const maybeUndefined: string | undefined = 'not actually undefined';
if (isNone(maybeUndefined)) {
return;
}
const anotherString = maybeUndefined + 'another string';
isNone(); // $ExpectType boolean
isNone(null); // $ExpectType boolean
isNone(undefined); // $ExpectType boolean
isNone(''); // $ExpectType boolean
isNone([]); // $ExpectType boolean
isNone(function() {}); // $ExpectType boolean
})();
示例5: isNone
(function() {
/** isNone */
const maybeUndefined: string | undefined = 'not actually undefined';
if (isNone(maybeUndefined)) {
return;
}
const anotherString = maybeUndefined + 'another string';
// TODO fix upstream in @types/ember https://github.com/typed-ember/ember-cli-typescript/issues/256
// isNone(); // $ExpectType boolean
isNone(null); // $ExpectType boolean
isNone(undefined); // $ExpectType boolean
isNone(''); // $ExpectType boolean
isNone([]); // $ExpectType boolean
isNone(function() {}); // $ExpectType boolean
})();
示例6: updateData
updateData(data: JsonApiResourceIdentity, initial: boolean) {
let recordData;
if (isNone(data)) {
recordData = null;
}
assert(
`Ember Data expected the data for the ${
this.key
} relationship on a ${this.recordData.toString()} to be in a JSON API format and include an \`id\` and \`type\` property but it found ${inspect(
data
)}. Please check your serializer and make sure it is serializing the relationship payload into a JSON API format.`,
data === null || (data.id !== undefined && data.type !== undefined)
);
if (recordData !== null) {
recordData = this.recordData.storeWrapper.recordDataFor(data.type, (data.id as string));
}
if (initial) {
this.setInitialCanonicalRecordData(recordData);
} else {
this.setCanonicalRecordData(recordData);
}
}
示例7: normalizeErrorResponse
* ```
*
* In cases where the server returns an array, then there should be one item
* in the array for each of the payload. If your server returns a JSON API
* formatted payload already, it will just be returned directly.
*
* If your server returns something other than a JSON API format, it's
* suggested that you override this method to convert your own errors into the
* one described above.
*/
normalizeErrorResponse(
status: number,
_headers: Headers,
payload?: Payload
): JsonApiErrorObject[] {
payload = isNone(payload) ? {} : payload;
if (isJsonApiErrorResponse(payload)) {
return payload.errors.map(function(error) {
if (isObject(error)) {
const ret = assign({}, error);
ret.status = `${error.status}`;
return ret;
} else {
return {
status: `${status}`,
title: error
};
}
});
} else if (isJsonApiErrorObjectArray(payload)) {
示例8: testIsNone
function testIsNone() {
utils.isNone(); // $ExpectType boolean
utils.isNone(''); // $ExpectType boolean
utils.isNone('', ''); // $ExpectError
}