Skip to content

Teamplate variable may get a wrong type? #1094

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

Closed
intijk opened this issue Dec 12, 2018 · 1 comment
Closed

Teamplate variable may get a wrong type? #1094

intijk opened this issue Dec 12, 2018 · 1 comment

Comments

@intijk
Copy link
Contributor

intijk commented Dec 12, 2018

I am trying to understand the code here.

type Provider<T, U> = (arg: T) => U
type Resolver<T, U> = (Provider<T, U> | boolean)[] | boolean
export = function tryChain<T, U> (resolvers: Array<Resolver<T, U>>, arg: T): U | void {
let response: U
for (let resolver of resolvers) {
if (!Array.isArray(resolver)) {
resolver = [resolver, true]
}
const [provider, condition] = resolver

In line 7, resolver is an element of resolvers, it might be an array or a boolean. If it is a boolean, it will construct resolver=[boolean, true] at line 9. And on line 11, provider will become a boolean. Is it intend to be designed this way?

@ulivz ulivz closed this as completed in 8daa159 Dec 12, 2018
@ulivz
Copy link
Member

ulivz commented Dec 12, 2018

Thanks for your report, but it's actually a typo (updated at 8daa159), a resolver could be a plain function which will be executed every time, or a array with resolving function as the 1st element and condition as the 2nd element which is for optional execution.

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

No branches or pull requests

2 participants