-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[gql-tag-operations-preset] Generated index.ts should contain \n regardless of whether source contains LF or CRLF #7362
Comments
We had a similar issue reported in #6811, and the following seems to be the most reasonable approach of solving it: #6811 (comment) Do you agree with that, would you like to help out documenting that or exploring alternative solutions? |
Hi @n1ru4l I don't think #6811 (comment) is the best solution because it won't help when a new source file is created on Windows. I can offer my help working on this issue. Empirically it seems that outputting |
It's seems that TypeScript does not differentiate between CRLF and LF - both become // This template literal contains CRLF as line breaks
type CRLF = `one
two
`;
// This template literal contains LF as line breaks
type LF = `one
two
`;
const test1: CRLF = 'one\r\ntwo\n'; // TS2322: Type '"one\r\ntwo\n"' is not assignable to type '"one\ntwo\n"'.
const test2: LF = 'one\r\ntwo\n'; // TS2322: Type '"one\r\ntwo\n"' is not assignable to type '"one\ntwo\n"'.
const test3: CRLF = 'one\ntwo\n'; // compilation passes
const test4: LF = 'one\ntwo\n'; // compilation passes I'll work on a PR. |
Fixed via #7369 |
I am having a similar issue, is this happening again? |
First of all, I would like to thank the creators of
gql-tag-operations-preset
, it's a really clever solution to have type safety while avoiding explicit imports.Describe the bug
TL;DR
Generated
index.ts
will cause TypeScript compilation to fail when source files contain CRLF (e.g. when using Windows).Long description
When source file contains LF, generated
index.ts
will contain \n and TypeScript will compile successfully.When source file contains CRLF, generated
index.ts
will contain \r\n and TypeScript will not compile.When source file contains CRLF, and generated
index.ts
is manually changed to contain \n, TypeScript will compile successfully.It seems that generated
index.ts
should contain\n
regardless of whether the source containsLF
orCRLF
.To Reproduce
NOTE: I have created a minimal reproduction example. It contains schema,
codegen.yml
and operations.Steps to reproduce the problem (using Linux):
1. Modify
src/app/app.tsx
by replacingLF
withCRLF
:New lines are now
CRLF
:2. Run
graphql-codegen
by executingnpm run generate
:The generated
index.ts
file will now contain\r\n
:3. Running
tsc
will now result in a compilation error:4. Now, if you go to generated
index.ts
and manually change all\r\n
to\n
and runtsc
again - it will compile.Environment
Additional info
This ticket suggests configuring
.gitattributes
to force using LF instead of CRLF on Windows. However, in my opinion it is not reasonable to ask users to change their CRLF strategy in order to work around this, it seems too invasive. Also, unless I'm missing something, it won't seem to help with source files created on Windows machine.The text was updated successfully, but these errors were encountered: