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

Allow all types as a key in $PropertyType. #2952

Closed
wants to merge 1 commit into from

Conversation

pvolok
Copy link
Contributor

@pvolok pvolok commented Dec 6, 2016

No description provided.

@pvolok
Copy link
Contributor Author

pvolok commented Dec 6, 2016

Fixed build error in gc_js.ml. Now CI should pass.

@facebook-github-bot
Copy link
Contributor

@samwgoldman has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@samwgoldman
Copy link
Member

Oh, interesting. It looks like the rules for InstanceT _, (GetElemT _ | SetElemT _) are a bit dumb and don't attempt to convert statically-known strings to named property lookups the way the corresponding rules for ObjT do.

Without that, code like this fails unexpectedly:

class C { p: number }
(0: $PropertyType<C, 'p'>);

If you are interested in something else to work on, we'd definitely need to resolve this issue before landing this change. If you're busy, I would be happy to take it on.

@samwgoldman samwgoldman self-assigned this Dec 13, 2016
@pvolok
Copy link
Contributor Author

pvolok commented Dec 14, 2016 via email

@szagi3891
Copy link

Why do not you integrate this PR?

@TheXardas
Copy link

I also need this feature as well!
When is it going to be merged?

@szagi3891
Copy link

@pvolok @samwgoldman
Do you have any plans for this "PR"?
This functionality will be very useful.

@asazernik
Copy link

@bradencanderson Or, for an example that may be more relevant to many followers of this issue:

class Record<Members: Object> {
  data: Members;

  constructor(data: Members) {
    this.data = data;
  }
  
  get<Key: string>(k: Key): $ElementType<Members, Key> {
      return this.data[k];
  }
}


type Thing = {
  a: number,
  b: string,
}
const constructorFailure: Record<Thing> = new Record({a: 1}) // error 
const r: Record<Thing> = new Record({a: 1, b: 'foo'});

(r.get('a'): string); // error
(r.get('a'): number);
(r.get('b'): number); // error
(r.get('b'): string);

In the sandbox.

@yachaka
Copy link

yachaka commented Jun 14, 2017

$ElementType definitely is the solution. Do you have an idea if this will be released with 0.49?

@pvolok pvolok closed this Jun 14, 2017
@STRML STRML mentioned this pull request Jun 14, 2017
20 tasks
@sergey-lapin
Copy link

@pvolok why it is closed? My guess you are not able to work on this anymore - can you comment if this is the case?

@pvolok
Copy link
Contributor Author

pvolok commented Jun 14, 2017

@Lapanoid Looks like $ElementType fixes the problem. Not sure if it works with classes though.

@sergey-lapin
Copy link

@pvolok Ahh I see, I thought it is released already, but it is only in master currently

@asazernik
Copy link

@Lapanoid Yeah, only landed in master on Sunday :-P

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

Successfully merging this pull request may close these issues.

9 participants