Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Zzzen opened this issue Mar 17, 2023 · 1 comment
Open

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

Zzzen opened this issue Mar 17, 2023 · 1 comment
Labels
area: fixers Around how TypeStat fixes code. status: accepting prs Please, send a pull request to resolve this! 馃檹 type: enhancement New feature or request

Comments

@Zzzen
Copy link

Zzzen commented Mar 17, 2023

馃悰 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

@JoshuaKGoldberg
Copy link
Owner

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 JoshuaKGoldberg added type: enhancement New feature or request status: accepting prs Please, send a pull request to resolve this! 馃檹 area: fixers Around how TypeStat fixes code. labels Mar 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: fixers Around how TypeStat fixes code. status: accepting prs Please, send a pull request to resolve this! 馃檹 type: enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants