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

Cannot convert deep-freeze definition file #189

Open
pdufour opened this issue Jun 28, 2022 · 0 comments
Open

Cannot convert deep-freeze definition file #189

pdufour opened this issue Jun 28, 2022 · 0 comments

Comments

@pdufour
Copy link

pdufour commented Jun 28, 2022

Hi there, I'm having troubles with deep-freeze library definition file and having a bit of trouble understanding how to fix it myself. Here is the definition file from typescript:
https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/deep-freeze/index.d.ts

Which gets converted to:

/**
 * Flowtype definitions for df.ts
 * Generated by Flowgen from a Typescript Definition
 * Flowgen v1.20.0
 */

// see https://gist.github.com/thecotne/6e5969f4aaf8f253985ed36b30ac9fe0
type $FlowGen$If<X: boolean, Then, Else = empty> = $Call<
  ((true, Then, Else) => Then) & ((false, Then, Else) => Else),
  X,
  Then,
  Else
>;

type $FlowGen$Assignable<A, B> = $Call<
  ((...r: [B]) => true) & ((...r: [A]) => false),
  A
>;

declare module.exports: typeof deepFreeze;
declare var deepFreeze: typeof npm$namespace$deepFreeze;

declare var npm$namespace$deepFreeze: {|
  <T>(a: T[]): $ReadOnlyArray<deepFreeze$DeepReadonly<T>>,
  <T: Function>(f: T): T,
  <T>(o: T): deepFreeze$DeepReadonly<T>,
|};
declare type deepFreeze$DeepReadonly<T> = $FlowGen$If<
  $FlowGen$Assignable<T, (...args: any) => any>,
  T,
  $ObjMapi<T, <P>(P) => deepFreeze$DeepReadonly<$ElementType<T, P>>>
>;

This seems to work for objects but not for arrays: https://flow.org/try/#0PQKhCgAIUgxAbA9gdwC4E8AOBTSATbAMwEsA7Y1YxUgZ0kMQCd9CA6VGqGAcW1O0YBDVNjyQARujhJkAcz71GiALaRBkACpZsNAMaNimVJAAiRMhSqku0lPNKQAbgEZWAJgAMrD12DhwwMCQNNi4ABaoqJg0AFyBssQ0qKwJqGEAruKsuirAadg5qPzAAGzYAKwAnCWVhAAsgoKEAByEbuUAzJXN5aIdJeIdHoK6tdg+GDiQACQIKLyk0wCShAA8ABoxEoiI8NiCpAA0mmF8xwCi8CGQALyQ2MpG6AB8tzMAwoLw8KtQkAAU-1QjHS2GOGlOR0glxCAEpbq8IXx4QAyAH-QhfELgyEXK7YeE3V4wgmHP7rMmQE5nP4k8DPADc-kmuFmMgW0wAgjQaMRZKRBOI9qtOccAEKvO7TT7fX5UwGsRWMLYAbTFAF1Ca9gaDUejFaxlZAVZzNQj6FjSX9OfSmeACLp4IJGLhlIg8Ok9qxsAAPTBMDhbFmIQj4UKYWAu7AAL2wTIdTpdTmdYewEajsaD2hDkFImGU0wFyh0mBG2GmBDTkdCsbtCeduEcKbzBaLJbLFfD1Zj2C2AG8AD5-VYaZ7-QRbDQqzVbaYAJX2eAA8qR4OhOYwhOhVpX0zXy2Y0wvBHhqGuR89npTICOtrB0qRdJRqGPCJPYZPrxf-oh31td92sbTIemDHqeq7bqOZIDgAvvGBSJrgLKpnuPbAeGYFnpBkozHMyAciscq4eyfBcjyfICkK2Ajsc-wGs6sixGopDoFqzEvNeGjXtMS7iAAVgAsoImDEDRN4AApjuJbEARmB4YYuWGrNMlwPHwqBaDgYmSZetr+P4gSQDktDGOodyyfu-x9jBsIBEEgisHgiSCnsYh3DqcbgMZSRqG8Fk9v8Kp-H2ABETk0C5oghVsmL4jBZKanZagqh46pvKFDCINFkAheIzohXBXnUD54hvIIKXqkyWThZFbmQB5TKGQ5mDpDQYT-AA5JlHWwgyQA

It generates the error:

const a = deepFreeze([
              ^ Cannot call `deepFreeze` because boolean literal `false` [1] is incompatible with boolean literal `true` [2] in the first argument. [invalid-call-util]
References:
29:   $FlowGen$Assignable<T, (...args: any) => any>,
      ^ [1]
9:   ((true, Then, Else) => Then) & ((false, Then, Else) => Else),
       ^ [2]

Compared to the typescript output which works correctly: https://www.typescriptlang.org/play?#code/FAEwpgxgNghgTmABAMwK4DsIBcCWB7dRcMABwDEEwAvMAHgBUA+AChgC5F6BtAXQEoOAJTAwQBKAE8AgnDgwJtYuUo0AdABEwpYaPEKmjANyhIsBCgzZ8hJRS00GiMAA8sYdCADOiMpdwEWZA56AU5jcGh4JDRMfxstZXs6JmY8YNDbFTANBJ0xdEkGI2ATSPN0GABbME8SGAgkTKTEAG9gRA7ELAkSJE1tEXzCpkQAXnbOyfonV3cvRGZVJfgAc08OGHQJPjHGRE2JCcnjxAB+TiOTzo4WxARdAolELgAFRBxCAGswCTxkTh4HH6JDyegYrx4ewAvsYoSUShACJ4sPsxkQEnZqGBmFwJi0AEQgHCeGAAIygYBA+I4yBgUE8YChABpgPxgIj0MjEKS0TAuAAGHjGUmqIkk8mUtFYOCoMCGIA

Any help appreciated.

Thank you!

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

1 participant