-
Notifications
You must be signed in to change notification settings - Fork 1
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
Refactor multiple old files to TypeScript #1010
Conversation
libs
to full typings
9ca7183
to
2fad88f
Compare
04f1438
to
50b5ed7
Compare
libs
to full typings36ba60f
to
789e91e
Compare
export const parseISOString = ISOString => { | ||
let b = ISOString.split(/\D+/) | ||
export const parseISOString = (ISOString: string): Date => { | ||
const b = ISOString.split(/\D+/).map(Number) | ||
return new Date(Date.UTC(b[0], --b[1], b[2], b[3], b[4], b[5], b[6])) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@paultranvan is it okay for you?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what it means for CozyGPSMemory: will it require some extra ts config?
I'm a bit worried that it may introduce more harm than good
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what it means for CozyGPSMemory: will it require some extra ts config? I'm a bit worried that it may introduce more harm than good
I don't think it should impact CozyGPSMemory, I think the issue here could be an unexpected behaviour at runtime with the casting to Number explicitly (this was required for stronger type inference).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the issue here could be an unexpected behaviour at runtime with the casting to Number explicitly
I'm not sure what you imply here: do you mean an issue could arise if the variable is actually not a number (which is normal), or that this issue could arise anyway?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed runtime modifications
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice one.
Only the comment about makeMetadata
is important, other ones are just nit and double-checks
!('url' in nativeEvent) || | ||
typeof nativeEvent.url !== 'string' | ||
) | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we throw instead? Can this happen?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't feel safe in throwing an error here as I don't know if the caller will expect it (fearing regressions). Logging a message instead then
if (!window.cozy) window.cozy = {} | ||
window.cozy.isFlagshipApp = true | ||
window.cozy.ClientKonnectorLauncher = 'react-native' | ||
window.cozy.ClientConnectorLauncher = 'react-native' // deprecated | ||
window.cozy.flagship = ${makeMetadata(routeName)} | ||
window.cozy.isSecureProtocol = ${isSecureProtocol || 'false'} | ||
window.cozy.flagship = ${routeName ? makeMetadata(routeName) : ''} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe whe should instead
window.cozy.flagship = ${makeMetadata(routeName ?? '')}
Seems like having an empty flagship
field would produce more side effect than having a wrong immersive
data
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
window.cozy.flagship = ${makeMetadata(routeName)} | ||
window.cozy.isSecureProtocol = ${isSecureProtocol || 'false'} | ||
window.cozy.flagship = ${routeName ? makeMetadata(routeName) : ''} | ||
window.cozy.isSecureProtocol = ${isSecureProtocol ? 'true' : 'false'} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isSecureProtocol ? 'true' : 'false'
seems weird
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree but TS doesn't like outputting non-string values in template literals in this case
nativeEvent: { | ||
data: string | ||
} | ||
} => ({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those types should definitively be extracted somewhere else. Inlining them make the code very difficult to read.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
const dataPayload = JSON.parse(rawData) as { | ||
type: string | ||
data?: { type: string; log: string[] } | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: would be more correct to remove this as
and to convert the next if
to a typeguard
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the issue is JSON methods all return any, have to cast them
It makes it harder to rename files to ts as they won't be resolved
Some runtime logic had to be updated, mostly adding more strict checks to avoid errors
These files are still used. Removed one unused file
789e91e
to
5aca8e0
Compare
Can't fix them right now. Will do after the big refactor branch is merged
fb50407
to
10e0a4e
Compare
Key Changes:
TypeScript Integration:
8b112609
), ensuring a more robust and error-resistant codebase.50b5ed73
), providing clearer interfaces and improving developer experience.File Renaming and Reorganization:
.ts
(8ef5488d
,a2ff6330
), aligning with TypeScript conventions and improving code consistency..ts
files to.tsx
where JSX is present (fbe4db2a
), ensuring proper file type representation and IDE support.Cleanup and Refinement:
63a75e73
), streamlining the code and reducing confusion around module systems.