jscodeshift
jscodeshift copied to clipboard
Parsing .d.ts files
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?
yeah if i have type definitions in my tsx file it throws with the "missing semicolon" error
@ceremonious try adding --parser=flow to the command at the command line, i think it is working for me
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