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

Narrowing #122

Closed
kaleidawave opened this issue Mar 3, 2024 · 2 comments · Fixed by #156
Closed

Narrowing #122

kaleidawave opened this issue Mar 3, 2024 · 2 comments · Fixed by #156
Labels
blocking These issues are blocking the checker being used in projects checking Issues around checking context Contexts (root or environment) enhancement New feature or request needs-investigation Further information is requested

Comments

@kaleidawave
Copy link
Owner

Using Type::Constructor information in a condition, it should be possible to record some truths that follow in the current block. Then getting-information-based-thingies should be able to read these recorded information and change results based from it.

This will use similar structs to the ones added (eventually) in #35

@kaleidawave kaleidawave added enhancement New feature or request needs-investigation Further information is requested checking Issues around checking context Contexts (root or environment) labels Mar 3, 2024
kaleidawave added a commit that referenced this issue Jun 3, 2024
- Currently basic equality
@kaleidawave kaleidawave linked a pull request Jun 3, 2024 that will close this issue
@kaleidawave kaleidawave added the blocking These issues are blocking the checker being used in projects label Jun 20, 2024
@kaleidawave
Copy link
Owner Author

Work started in #156

There should be a new type Type::Narrowed { /* points to a poly type */ on: TypeId, narrowed: TypeId }. This retains some information through on but contains narrowed which replaces the base type (get_constraint should be changed to look this up).

@kaleidawave
Copy link
Owner Author

Note that there are some problems when narrowing properties. In the case that the property is a getter the following has a type error that is not caught by TSC.

function func(param: { a: number | string }) {
	if (typeof param.a === "number") {
		return Math.sin(param.a)
	}
}

func({ get param() { return Date.now() % 2 ? 5 : "string "} })

Half the time this will fail (produce undesired results in this example) at runtime.

Some thoughts

  • Don't narrow properties
  • Maybe a special type for disallowing getters or impure getters
  • Track narrowing via events

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocking These issues are blocking the checker being used in projects checking Issues around checking context Contexts (root or environment) enhancement New feature or request needs-investigation Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant