我有一个关于typescript属性的问题:是否可以获取typescript属性的setter和getter,或者将函数参数声明为X类型的属性?原因是为了获得对变量的某种“引用”,这在普通的JS中是不可能的,除非编写getter/setter包装器,或者通过父对象本身访问变量(obj"varname")。modifing a member "by reference"
class Mo
我使用带有typescript和namespaces模块的vuex。我有两个模块:"UserProfile“和"Trips”。所有的工作都在一个模块中进行。据我所知,如果我不使用类型环回,我可以使用rootState"profile/user“。但是在使用typescript时,编译器会给我一个这样的错误:
Element implicitly has an 'any' type because type 'RootState' has no=
MyClassWithSetterOnly implements IMyInterface { // <--- Expect error, because property1 is missing a gettermissing a setter
console.log(setterOnly.property1); // <--- Expect error, because property1 is missing a getterconsole.log(getterOnly.property1); <e
TypeScript Playground 我希望能够使用Getter接口的实现,或者在泛型中指定返回类型,或者在标准类型赋值中描述返回类型。在这两种情况下,类型都需要看起来像一个简单的对象,所以我扩展了一个Record,以便在类型不匹配(如number或string)时鼓励编译器出错。 当没有提供类型时,假设它是一个无类型的简单对象。: Getter = {} as any
const va