TypeStat icon indicating copy to clipboard operation
TypeStat copied to clipboard

JSDoc type info are not read when converting from js to ts

Open Zzzen opened this issue 2 years ago • 1 comments

🐛 Bug Report

  • TypeStat version: 0.6.3
  • TypeScript version: 4.7.4
  • Node version: v16.15.0

original js file

/*
 * Utility function to compile a WebGL Vertex or Fragment shader.
 *
 * @param {WebGLRenderingContext} gl - the webgl context fo which to build the shader.
 * @param {String} shaderSource - A string of shader code to compile.
 * @param {number} shaderType - Shader type, either WebGLRenderingContext.VERTEX_SHADER or WebGLRenderingContext.FRAGMENT_SHADER.
 *
 * @return {WebGLShader} A compiled shader.
 *
 */
export function compileShader(gl, shaderSource, shaderType) {
    let shader = gl.createShader(shaderType);
    gl.shaderSource(shader, shaderSource);
    gl.compileShader(shader);
    let success = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
    if (!success) {
        throw "could not compile shader:" + gl.getShaderInfoLog(shader);
    }
    return shader;
}

Actual Behavior

/*
 * Utility function to compile a WebGL Vertex or Fragment shader.
 *
 * @param {WebGLRenderingContext} gl - the webgl context fo which to build the shader.
 * @param {String} shaderSource - A string of shader code to compile.
 * @param {number} shaderType - Shader type, either WebGLRenderingContext.VERTEX_SHADER or WebGLRenderingContext.FRAGMENT_SHADER.
 *
 * @return {WebGLShader} A compiled shader.
 *
 */
export function compileShader(gl: { VERTEX_SHADER?: any; FRAGMENT_SHADER?: any; getParameter?: (arg0: any) => any; MAX_TEXTURE_IMAGE_UNITS?: any; texImage2D?: (arg0: any,arg1: number,arg2: any,arg3: any,arg4: any,arg5: number,arg6: any,arg7: any,arg8: any) => void; TEXTURE_2D?: any; RGBA?: any; canvas?: { width: any; height: any; }; UNSIGNED_BYTE?: any; createFramebuffer?: () => any; bindFramebuffer?: (arg0: any,arg1: any) => void; FRAMEBUFFER?: any; framebufferTexture2D?: (arg0: any,arg1: any,arg2: any,arg3: any,arg4: number) => void; COLOR_ATTACHMENT0?: any; TEXTURE0?: number; getUniformLocation?: (arg0: any,arg1: any) => any; getAttribLocation?: (arg0: any,arg1: string) => any; createBuffer?: () => any; bindBuffer?: (arg0: any,arg1: any) => void; ARRAY_BUFFER?: any; enableVertexAttribArray?: (arg0: any) => void; vertexAttribPointer?: (arg0: any,arg1: number,arg2: any,arg3: boolean,arg4: number,arg5: number) => void; FLOAT?: any; bufferData?: (arg0: any,arg1: Float32Array,arg2: any) => void; STATIC_DRAW?: any; createShader?: any; shaderSource?: any; compileShader?: any; getShaderParameter?: any; COMPILE_STATUS?: any; getShaderInfoLog?: any; }, shaderSource, shaderType) {
    let shader = gl.createShader(shaderType);
    gl.shaderSource(shader, shaderSource);
    gl.compileShader(shader);
    let success = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
    if (!success) {
        throw "could not compile shader:" + gl.getShaderInfoLog(shader);
    }
    return shader;
}

Expected Behavior

/*
 * Utility function to compile a WebGL Vertex or Fragment shader.
 *
 * @param {WebGLRenderingContext} gl - the webgl context fo which to build the shader.
 * @param {String} shaderSource - A string of shader code to compile.
 * @param {number} shaderType - Shader type, either WebGLRenderingContext.VERTEX_SHADER or WebGLRenderingContext.FRAGMENT_SHADER.
 *
 * @return {WebGLShader} A compiled shader.
 *
 */
export function compileShader(gl: WebGLRenderingContext, shaderSource: string, shaderType: number) {
    let shader = gl.createShader(shaderType);
    gl.shaderSource(shader, shaderSource);
    gl.compileShader(shader);
    let success = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
    if (!success) {
        throw "could not compile shader:" + gl.getShaderInfoLog(shader);
    }
    return shader;
}

Reproduction

Run typestat on https://github.com/bbc/VideoContext/blob/develop/src/utils.js

Zzzen avatar Mar 17 '23 06:03 Zzzen

Indeed, this would be very nice. And I think a lot of projects migrating to TS -especially those that already // @ts-check files- would benefit from JSDoc detection.

Accepting PRs, but note - this is likely a pretty big task.

JoshuaKGoldberg avatar Mar 19 '23 13:03 JoshuaKGoldberg