chore(ts): Convert src/sentry/static/sentry/app/utils.jsx to typescript#14199
chore(ts): Convert src/sentry/static/sentry/app/utils.jsx to typescript#14199
Conversation
| function objectMatchesSubset(obj, other, deep) { | ||
| let k; | ||
| function objectMatchesSubset(obj?: object, other?: object, deep?: boolean): boolean { | ||
| let k: string | number; |
There was a problem hiding this comment.
Why number, shouldn't it always be string?
There was a problem hiding this comment.
@lynnagara I thought so too. I used vscode to infer the type for me:
There was a problem hiding this comment.
Is this because array is a valid type of object (keys are just numbers instead of strings?). In our usage of this function I think it should only be an object with key as string.
| } | ||
|
|
||
| export function intcomma(x) { | ||
| export function intcomma(x: object): string { |
| } | ||
| return result; | ||
| export function objectToArray<T>( | ||
| obj: {[s: string]: T} | ArrayLike<T> |
There was a problem hiding this comment.
When is it not a regular object?
There was a problem hiding this comment.
I'm just going to use export const objectToArray = Object.entries;
| } | ||
|
|
||
| function projectDisplayCompare(a, b) { | ||
| interface Project { |
There was a problem hiding this comment.
| return typeof feature.match !== 'function' | ||
| ? feature | ||
| : feature.match(/(?:^(?:projects|organizations):)?(.*)/).pop(); | ||
| export function descopeFeatureName(feature: string): string { |
There was a problem hiding this comment.
This (feature) seems like it's not always a string
There was a problem hiding this comment.
where is it not a string?
There was a problem hiding this comment.
If it's always a string then line 222 - 224 doesn't make sense
There was a problem hiding this comment.
Ah hm, I forget why I wrote it like that 😬
There was a problem hiding this comment.
I've adjusted the types for this function
| } | ||
|
|
||
| return Object.freeze(object); | ||
| return Object.freeze<T>(object); |
There was a problem hiding this comment.
Is there value in this type annotation? We could probably drop this
| const match = repo.match(re); | ||
| const parsedRepo = match ? match[1] : repo; | ||
| return parsedRepo; | ||
| return parsedRepo as any; |
| slug: string; | ||
| isMember: boolean; | ||
|
|
||
| isBookmarked?: boolean; |
There was a problem hiding this comment.
Might not need to be optional? AFAIK we always get an isBookmarked value for a project
| } | ||
| return result; | ||
| } | ||
| export const objectToArray = Object.entries; |
There was a problem hiding this comment.
Could we refactor this method away? I don't see there being much value in having an alias to stdlib.
| } | ||
| return result; | ||
| } | ||
| export const objectToArray = Object.entries; |
There was a problem hiding this comment.
I wonder if this will have implications, since right now this would iterate keys like constructor. Not sure if Object.entries will do that as well.
There was a problem hiding this comment.
I don't think we ever want to iterate keys like constructor, Object.entries only iterates its own properties.
There was a problem hiding this comment.
Good points. I'll revisit this to see if the refactor is generally small enough to fit into this PR.
I don't want to accidentally introduce a bug by "correcting" this utility function.
There was a problem hiding this comment.
Let's not tackle it here, IMO we should fix it though, I recall a case of a project named "constructor" recently that did have some problems.
| return results.pop()!; | ||
| } | ||
|
|
||
| return feature; |
There was a problem hiding this comment.
Personal preference, but I think the original shorter version was easier to read (But I'm also biased, because I wrote it)
There was a problem hiding this comment.
Even this last bit I think could just be return results ? results.pop() : feature
There was a problem hiding this comment.
@evanpurkhiser oh interesting. I'll revisit this.
Typescript indicated that the match() can return null, which is why I rewrote it like this.
d97d3f3 to
544f071
Compare
157984f to
496fb5c
Compare
3b25e34 to
0f2f85a
Compare
0f2f85a to
76c29ca
Compare
76c29ca to
92b3a4f
Compare

TODO
descopeFeatureName()Deferred to another followup PR