electricessence / TypeScript.NET

A JavaScript-Friendly .NET Based TypeScript Library (Moved)
https://github.com/electricessence/TypeScript.NET-Core
Other
251 stars 36 forks source link

Usage with Angular 2 / Angular CLI #60

Closed bam-dreymers closed 7 years ago

bam-dreymers commented 7 years ago

Keeping in mind - I am a novice user. That being said...

Using the basic @angular/cli setup for an Angular project, files with only a ".d.ts" extension and no ".ts" file - cannot be referenced.

I installed in the web app using "npm install typescript-dotnet --save".

Example - in a component: import { DateTime } from "typescript-dotnet/source/System/Time/DateTime";

...then inside the component code somewhere: let x = new DateTime("20170302T110000Z");

Gets an error when transpiling": Module not found: Error: Can't resolve './HowMany' in '...\node_modules\typescript-dotnet\source\System\Time' @ ./~/typescript-dotnet/source/System/Time/DateTime.ts 3:0-41

I noticed this is evident with any files that only have a ".d.ts" but not ".ts" file. Again - I'm not a JS guy, but I'm hoping there's some easy solution. I read through the comments about some problems with webpack, and I know angluar CLI uses webpack, but having novice understanding just couldn't figure out what that was all about.

Any advice would be appreciated, because this is such a great project and would be crazy helpful.

electricessence commented 7 years ago

No pun intended, but are you on a time crunch? I'll try to get to this in the next day. K?

bam-dreymers commented 7 years ago

lol - good one :-) Thanks for the quick reply!

Not an urgent issue at the moment. Interestingly enough, when I get a DateTime formatted JSON from the API and deserialize then it poses no problem, and I'm then able to use the Angular Date pipe on it - that all flows with no issues.

It's only when I attempt to either new a DateTime or use any of the functions (like toJsDate(), for example) that it complains.

I really appreciate your attention to this. It's obvious you've put a great deal of work into this, and being a .NET guy working in client code there's just so much in typescript.net that seems just really fantastic!

On Wed, Mar 29, 2017 at 9:43 PM, electricessence notifications@github.com wrote:

No pun intended, but are you on a time crunch? I'll try to get to this in the next day. K?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/electricessence/TypeScript.NET/issues/60#issuecomment-290300977, or mute the thread https://github.com/notifications/unsubscribe-auth/AWjGlK0XYSwX7qLeAmjYcKdAPEpB8xbnks5rqzMEgaJpZM4Mt27U .

-- David Reymers Be A Mentor, Inc. (510) 795-6488 dreymers@beamentor.org

electricessence commented 7 years ago

Ok... So here's what you have to do...

var serializableDate = myDateTime.toJsDate();

Obviously you can't serialize the function itself. DateTime is not inherently JSON serializable.

electricessence commented 7 years ago

Get back to me if this solves your problem.

electricessence commented 7 years ago

OHHHH... One more VERY IMPORTANT DETAIL:

import { DateTime } from "typescript-dotnet/source/System/Time/DateTime";

The above is BAD.

You need to use the commonjs or UMD versions like this:

import { DateTime } from "typescript-dotnet-commonjs/System/Time/DateTime";

or

import { DateTime } from "typescript-dotnet-umd/System/Time/DateTime";

So change your dependency references for typescript-dotnet to typescript-dotnet-commonjs or typescript-dotnet-umd.

bam-dreymers commented 7 years ago

Thanks, I'm using commonjs and now it works. Almost....

One problem I still have is referencing the Kind enum. I get the message "TypeError: Cannot read property 'Utc' of undefined".

Any ideas?

On Wed, Mar 29, 2017 at 11:24 PM, electricessence notifications@github.com wrote:

OHHHH... One more VERY IMPORTANT DETAIL:

import { DateTime } from "typescript-dotnet/source/System/Time/DateTime";

The above is BAD.

You need to use the commonjs or UMD versions like this:

import { DateTime } from "typescript-dotnet-commonjs/System/Time/DateTime";

or

import { DateTime } from "typescript-dotnet-umd/System/Time/DateTime";

So change your dependency references for typescript-dotnet to typescript-dotnet-commonjs or typescript-dotnet-umd.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/electricessence/TypeScript.NET/issues/60#issuecomment-290314159, or mute the thread https://github.com/notifications/unsubscribe-auth/AWjGlMXTaZ6sAoZLWzcS17Aa1nqcBd4Kks5rq0qdgaJpZM4Mt27U .

-- David Reymers Be A Mentor, Inc. (510) 795-6488 dreymers@beamentor.org

electricessence commented 7 years ago

Hey. So the DateTime.Kind.Utc is part of a const enum which means that it's only a number. It has to 'compile' under TS for it to work. If you reference it at runtime just as you would at compile time, then it will throw that error becase Kind doesn't actually exists.

This has an easy fix. I can not make it a const and it will then be exposed at run time.

electricessence commented 7 years ago

https://github.com/electricessence/TypeScript.NET/commit/33cd6ad4c116dafe1cd553d70fa0dba5d1ec5203

electricessence commented 7 years ago

@bam-dreymers Lemme know if that fixes your issue. You'll need to update.

bam-dreymers commented 7 years ago

Cool, thanks. I'll give it a try and let you know :-)

On Apr 2, 2017 1:25 PM, "electricessence" notifications@github.com wrote:

33cd6ad https://github.com/electricessence/TypeScript.NET/commit/33cd6ad4c116dafe1cd553d70fa0dba5d1ec5203

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/electricessence/TypeScript.NET/issues/60#issuecomment-291012414, or mute the thread https://github.com/notifications/unsubscribe-auth/AWjGlDFQkN8PLgAj4SC-cfclAnYX4ZGFks5rsARRgaJpZM4Mt27U .

bam-dreymers commented 7 years ago

Yes, that worked - thanks!

On Sun, Apr 2, 2017 at 1:28 PM, David Reymers dreymers@beamentor.org wrote:

Cool, thanks. I'll give it a try and let you know :-)

On Apr 2, 2017 1:25 PM, "electricessence" notifications@github.com wrote:

33cd6ad https://github.com/electricessence/TypeScript.NET/commit/33cd6ad4c116dafe1cd553d70fa0dba5d1ec5203

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/electricessence/TypeScript.NET/issues/60#issuecomment-291012414, or mute the thread https://github.com/notifications/unsubscribe-auth/AWjGlDFQkN8PLgAj4SC-cfclAnYX4ZGFks5rsARRgaJpZM4Mt27U .

-- David Reymers Be A Mentor, Inc. (510) 795-6488 dreymers@beamentor.org

electricessence commented 7 years ago

@bam-dreymers Great. Please close the issue. :)