at the class getter property,why is need it initialize, if not then report error code is ts(2739)
nczsl opened this issue Β· comments
nczsl commented
π Search Terms
ts(2739)
π Version & Regression Information
- This is a crash
- This changed between versions ______ and _______
- This changed in commit or PR _______
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________
- I was unable to test this on prior versions because _______
code -v :
1.89.1
dc96b837cf6bb4af9cd736aa3af08cf8279f7685
x64
tsc -v :
Version 5.4.5
β― Playground Link
No response
π» Code
class CanvasInfo {
// canvas:HTMLCanvasElement;
context: GPUCanvasContext;
format: GPUTextureFormat;
renderDescriptor: GPURenderPassDescriptor;
constructor(){}
get width(): number {
return this.context.canvas.width;
}
get height(): number {
return this.context.canvas.height;
}
}
//------------------------------------------
let cinfo: /**here display the rad under line ,report error code is ts(2739)*/CanvasInfo = {
context,
format,
renderDescriptor: {
colorAttachments: [{
view: context.getCurrentTexture().createView(),
loadOp: 'clear',
storeOp: 'store',
clearValue: color ? { r: color.x, g: color.y, b: color.z, a: color.w } : { r: 0.30, g: 0.0, b: 0.0, a: 1.0 }
}],
depthStencilAttachment: {
view: depthTexture.createView(),
depthLoadOp: 'clear',
depthStoreOp: 'store',
depthClearValue: 1.0,
}
},
// width: canvas.width,
// height: canvas.height
};
π Actual behavior
the width/height in CanvasInfo class is a getter ,why need initialize?
π Expected behavior
getter property is need provide,
Additional information about the issue
at the class getter property,why is need it initialize, if not then report error code is ts(2739)
Martin Johns commented
This is working as intended.
You're assigning an object literal to your variable, and the object literal is not an instance of the class and thus won't have the getters.
nczsl commented
let cinfo: CanvasInfo = new CanvasInfo();
cinfo.context = context;
cinfo.format = format;
cinfo.renderDescriptor = {
colorAttachments: [{
view: context.getCurrentTexture().createView(),
loadOp: 'clear',
storeOp: 'store',
clearValue: color ? { r: color.x, g: color.y, b: color.z, a: color.w } : { r: 0.30, g: 0.0, b: 0.0, a: 1.0 }
}],
depthStencilAttachment: {
view: depthTexture.createView(),
depthLoadOp: 'clear',
depthStoreOp: 'store',
depthClearValue: 1.0,
}
};
I modified it to be correct, it meets expectations.