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

Refactor to TypeScript and ship types #71

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

charlesfries
Copy link

Fixes #67

@jelhan jelhan changed the title Install TypeScript Refactor to TypeScript and ship types Aug 20, 2024
@jelhan jelhan added the enhancement New feature or request label Aug 20, 2024
Copy link
Owner

@jelhan jelhan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for picking this up!

I haven't had the time doing a full review. But as I have some draft comments pending since a few days I felt sending them as-is is better than letting you wait longer.

Additionally to the inline comments, it would be great if you could convert the tests to TypeScript as well. That gives us test coverage for the types.

@@ -22,19 +22,23 @@ window.addEventListener('storage', function ({ key, newValue }) {
return;
}

localStorageCache.set(key, jsonParseAndFreeze(newValue));
localStorageCache.set(key, jsonParseAndFreeze(newValue as string));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we guard against newValue being null instead of doing a type assertion?

addon/index.ts Outdated Show resolved Hide resolved
addon/index.ts Outdated
@@ -79,7 +84,7 @@ export function initalizeLocalStorageKey(key) {
managedKeys.add(key);
localStorageCache.set(
key,
jsonParseAndFreeze(window.localStorage.getItem(key))
jsonParseAndFreeze(window.localStorage.getItem(key) as string)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should handle the null case explicitly instead of doing a type assertion.

addon/index.ts Outdated Show resolved Hide resolved
@charlesfries
Copy link
Author

Still working on these fixes. One question--when the decorator is used without arguments (isDirectDecoratorInvocation), TypeScript expects the decorator return type to be void or any. However for that condition it appears the factory returns the result of the internal decorator function, which is that get/set object.

Are you able to shed any light on that logic?

@charlesfries
Copy link
Author

charlesfries commented Aug 23, 2024

Also, where does that initializer function on the descriptor come from? Couldn't find any info on that

@jelhan
Copy link
Owner

jelhan commented Aug 24, 2024

Still working on these fixes. One question--when the decorator is used without arguments (isDirectDecoratorInvocation), TypeScript expects the decorator return type to be void or any. However for that condition it appears the factory returns the result of the internal decorator function, which is that get/set object.

Are you able to shed any light on that logic?

The issue might be caused by wrong return type declaration for localStorageDecoratorFactory. It's typed as void. But I think it should be a PropertyDescriptor.

I expect that the current function signature also causes a TypeScript error when the decorator is used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

convert to TypeScript
2 participants