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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parsing .d.ts files #539

Open
ceremonious opened this issue Dec 28, 2022 · 3 comments
Open

Parsing .d.ts files #539

ceremonious opened this issue Dec 28, 2022 · 3 comments

Comments

@ceremonious
Copy link

ceremonious commented Dec 28, 2022

Is it possible to use jscodeshift to modify .d.ts files?

I'm trying to parse a file that looks like this:

import * as runtime from '@prisma/client/runtime/index';
declare const prisma: unique symbol
export type PrismaPromise<A> = Promise<A> & {[prisma]: true}
type UnwrapPromise<P extends any> = P extends Promise<infer R> ? R : P
type UnwrapTuple<Tuple extends readonly unknown[]> = {
  [K in keyof Tuple]: K extends `${number}` ? Tuple[K] extends PrismaPromise<infer X> ? X : UnwrapPromise<Tuple[K]> : UnwrapPromise<Tuple[K]>
};

export type PrismaVersion = {
  client: string
}

export const prismaVersion: PrismaVersion 

//...more content

If I use Babel as a parser, I get this error: SyntaxError: Missing semicolon. (2:7)

If I use Typescript, I get this error: SyntaxError: Missing initializer in const declaration. (13:41)

Is there a different parser or parser config I can use?

@goughjo02
Copy link

yeah if i have type definitions in my tsx file it throws with the "missing semicolon" error

@goughjo02
Copy link

@ceremonious try adding --parser=flow to the command at the command line, i think it is working for me

@NullVoxPopuli
Copy link

parser=flow to the command at the command line, i think it is working for me

the parsing is successful, but output doesn't match.

For example, I'm seeing

export declare const two: number;

converted to

export declare var two: number;

This changes expectations around mutability

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants