stc icon indicating copy to clipboard operation
stc copied to clipboard

Modify function type on property assignment

Open kdy1 opened this issue 2 years ago • 4 comments

Problem

https://github.com/dudykr/stc/blob/efd873e395fb9327f6cbd8be76a24678013269c4/crates/stc_ts_type_checker/tests/conformance/salsa/typeFromPropertyAssignment29.ts#L2-L9

Currently, stc does not support adding a property to type by assigning a property to function. But the function type is special, and we should support it.

kdy1 avatar Nov 07 '22 07:11 kdy1

Hi, I would like to take a look at this issue, but I am not sure how to proceed with this. This is what I have thought of so far:

  • I probably have to modify access_property_inner() in crates/stc_ts_file_analyzer/src/analyzer/expr/mod.rs when checking property access for Type::Function.
  • I will need to modify the Function struct in crates/stc_ts_types/src/lib.rs, so that we have a place to store function properties.

I am not sure where is the best place for the logic to update the Function struct with the function properties though.

yamgent avatar Nov 19 '22 09:11 yamgent

I think the ideal way is to add a type literal (for intersection) on each assignment, not access_property

kdy1 avatar Nov 19 '22 10:11 kdy1

Shared mutability is a hard topic in rust. Actually, we don't mutate types from multiple threads, so we don't need a mutex but Type has to be Send, and it's sometimes wrapped in Arc to reduce memory usage. So we should not modify it in-place

kdy1 avatar Nov 19 '22 13:11 kdy1

I think that this function type mean Module type module type is callable and have a property

and

ts playground says next image

sunrabbit123 avatar Aug 14 '23 09:08 sunrabbit123