本文整理汇总了TypeScript中@ember/object/computed.alias函数的典型用法代码示例。如果您正苦于以下问题:TypeScript alias函数的具体用法?TypeScript alias怎么用?TypeScript alias使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了alias函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: set
set(key, value) {
const [first, last] = value.split(' ');
this.set('firstName', first);
this.set('lastName', last);
return value;
}
}),
combinators: Ember.computed<string>(function() {
return this.get('firstName');
}).property('firstName')
.meta({ foo: 'bar' })
.volatile()
.readOnly(),
explicitlyDeclared: alias('fullName') as Computed<string>,
});
const person = Person.create({
firstName: 'Fred',
lastName: 'Smith',
age: 29,
});
assertType<string>(person.firstName);
assertType<number>(person.age);
assertType<Ember.ComputedProperty<string>>(person.noArgs);
assertType<Ember.ComputedProperty<string>>(person.fullName);
assertType<Ember.ComputedProperty<string>>(person.fullNameReadonly);
assertType<Ember.ComputedProperty<string>>(person.fullNameWritable);
assertType<Ember.ComputedProperty<string>>(person.fullNameGetOnly);
示例2: service
import { alias } from '@ember/object/computed';
export default Mixin.create({
/**
* The AJAX service to send requests through
*
* @property {AjaxService} ajaxService
* @public
*/
ajaxService: service('ajax'),
/**
* @property {string} host
* @public
*/
host: alias('ajaxService.host'),
/**
* @property {string} namespace
* @public
*/
namespace: alias('ajaxService.namespace'),
/**
* @property {object} headers
* @public
*/
headers: alias('ajaxService.headers'),
ajax(url: string, _method: string, _options: object) {
// @ts-ignore
示例3: set
set(key, value) {
const [first, last] = value.split(' ');
this.set('firstName', first);
this.set('lastName', last);
return value;
}
}),
combinators: computed<string>(function() {
return this.get('firstName');
}).property('firstName')
.meta({ foo: 'bar' })
.volatile()
.readOnly(),
explicitlyDeclared: alias('fullName') as ComputedProperty<string>,
});
const person = Person.create({
firstName: 'Fred',
lastName: 'Smith',
age: 29,
});
assertType<string>(person.firstName);
assertType<number>(person.age);
assertType<ComputedProperty<string>>(person.noArgs);
assertType<ComputedProperty<string>>(person.fullName);
assertType<ComputedProperty<string>>(person.fullNameReadonly);
assertType<ComputedProperty<string>>(person.fullNameWritable);
assertType<ComputedProperty<string>>(person.fullNameGetOnly);