本文整理匯總了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
}