Comments (12)
Changed parser to just eat up the generics, no change to the AST yet.
See https://github.com/angular/angular/blob/master/tools/js2dart/src/parser.js#L12
from angular.
Traceur has just added support for generics, see google/traceur-compiler@32aadd5
from angular.
This means @InjectPromise(UserList) userList
should be changed to userList: Promise<UserList>
with regards to di injection, right?
from angular.
Here is my understanding of the state of this feature (@vicb can correct me):
Traceur does parse the generics (type arguments). That is all.
We are missing:
- generate runtime annotations
- generate runtime type assertions (probably the same format as annotations)
- output the generics in the dart code
- output the generics in the ES6 code (we don't need this, but would be nice)
How do we generate type annotations and runtime type assertions? I suggest this:
function foo(a: Bar, b: Bar<Baz>) {}
// Currently we generate this:
foo.parameters = [[Bar]];
// I suggest to generate this:
foo.parameters = [[new TypeAnnotation(Bar)], [new TypeAnnotation(Bar, Baz)]];
That means, traceur-runtime need to define the TypeAnnotation
class.
How about type assertions? Should we do something like this?
function foo(a, b) {
assert.argumentTypes(a, new TypeAnnotation(Bar), b, new TypeAnnotation(Bar, Baz));
}
from angular.
I was thinking something along these lines:
function foo(a: Bar, b: Bar<Baz>) {}
foo.parameters = [Bar, Bar.parameterize(Baz)];
This means that only types which define parameterize
method can be generecized. The purpose of the parameterize
is to crate (or returned a cache) of a new type which is parameterize on such a type an which can than be used for assertions as normal.
Thoughts?
from angular.
@mhevery That would indicate that if I write a generic class, it would generate a parameterize
static method automagically?
from angular.
@mhevery I like this! It would be good to limit the amount of garbage we create.
@Alxandr yes, we can generate the .parameterize
method. That just reminds me we need one more thing - update the parser to allow class Foo<...>
so that you can actually define parametrizable types. For these, Traceur would also generate the parametrize
method.
from angular.
So here's the updated list of tasks:
- parse
class Foo<Bar, Baz>
(and generateparametrize
method), see google/traceur-compiler#1525 - output the generics in the dart code
- generate runtime annotations
- generate runtime type assertions (probably the same format as annotations)
- make sure
$traceurRuntime.genericType(A2, B2, C2) === $traceurRuntime.genericType(A2, B2, C2)
, see google/traceur-compiler#1523 - update rtts_assert library to deal with generics
- output the generics in the ES6 code (we don't need this, but would be nice)
from angular.
I'm going to work on this today.
from angular.
For Traceur, I currently transform the TypeReference
A<B, C>
to
$traceurRuntime.genericType(A2, B2, C2);
// where A2 is the transformed A
which in turn creates a new instance of $traceurRuntime.GenericType
. The last step is important so that the assertion library can do instanceof
to see if it is a generic.
google/traceur-compiler@633acbc#diff-c5472491bfb53e84718d853046894688R39
This is all very adhoc at the moment.
from angular.
We actually never removed our hack from our transpiler, so we never used the new feature from traceur. See #554
from angular.
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.
from angular.
Related Issues (20)
- hostDirectives deep input mapping works implicitly and not explicitly HOT 3
- Ancors on page doesn't lead to specific id's HOT 2
- Link leads to Page Not Found
- docs: ng new not easy to find as a learner on angular.dev HOT 2
- bug: Go to definition doesn't work on the second component in a single file HOT 3
- docs: Reactive Forms disable/enable functions are not part of the Reactive Forms guide
- `await deferBlockFixture.render` hangs when `interval` is subscribed HOT 1
- angular tutorial HOT 1
- contentChild support locator array HOT 2
- angular signal not updating when using afterNextRender() HOT 3
- prerender.io compatibility with hydration HOT 9
- Angular Animations - fade in / out works for DIVs, not fully for child components (not sure if bug) HOT 2
- how to handle "document is not defined" in ng17 ssr HOT 7
- Updating a BehaviorSubject too quickly fails to trigger change detection HOT 1
- Angular SSR does not call API on every page request HOT 2
- Computed signal and effect don't recompute if non signal boolean value included in computation as first check in condition. HOT 7
- Clear terminal when running projects HOT 1
- After Upgrade to Angular 17 loader not working which added in app.component.html file HOT 4
- Type for @NgModule.imports is not compatible with recommended standalone group export HOT 1
- Disable dev tools by code? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from angular.