-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[trusted-types] Add $Trusted/$Private type annotations
Summary: Adding preliminary syntax for trusted type annotations, `$Trusted<T>` and `$Private<T>`. Right now these types are no-ops and are equivalent to `T`, but trusted typing will use `$Trusted<T>` to mean the same thing as the more compact syntax for trusted types (tentatively `*T`): it is a non-supertype of `any` while behaving like `T` otherwise. The `$Private<T>` annotation is something that programmers shouldn't have to worry about (because it will be inferred where needed); essentially it is a non-*sub*type of `any` in the same way that trusted types are non-supertypes of `any`. The `$Private` syntax will exist for testing purposes and maybe niche use cases. * `$Trusted<any>` and `$Private<any>` are invalid types, mainly because they don't really make sense semantically. * Only `DefT`s can be made trusted or private, at least for now. This does mean that we can't write the following: ```type T = number var x: $Trusted<T> = 42; ``` * I think this is a restriction that should eventually be able to be lifted, but it might not be trivial to implement trusted non-`DefT`s in the type system--hence keeping this restriction right now. Reviewed By: dsainati1 Differential Revision: D13867988 fbshipit-source-id: 47e994e9f20b9b80cb9fb2aab434bab7d6575437
- Loading branch information
1 parent
306096a
commit fa0a8ef
Showing
8 changed files
with
75 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,6 @@ | |
type trust | ||
|
||
val bogus_trust: unit -> trust | ||
|
||
val make_trusted: trust -> trust | ||
val make_private: trust -> trust |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
//@flow | ||
|
||
declare function f(x: $Trusted<number>): $Private<number>; | ||
declare var x: $Trusted<$Private<($Private<number>)=>$Trusted<number>>>; | ||
declare var y: $Trusted<any>; | ||
type T = $Trusted<number>; | ||
declare var z: $Trusted<T> | ||
(32: $Trusted<number>) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
Error --------------------------------------------------------------------------------------------------- syntax.js:5:16 | ||
|
||
Not a valid type to mark as `$Trusted`. | ||
|
||
5| declare var y: $Trusted<any>; | ||
^^^^^^^^^^^^^ | ||
|
||
|
||
Error --------------------------------------------------------------------------------------------------- syntax.js:7:16 | ||
|
||
Not a valid type to mark as `$Trusted`. | ||
|
||
7| declare var z: $Trusted<T> | ||
^^^^^^^^^^^ | ||
|
||
|
||
|
||
Found 2 errors |