-
Notifications
You must be signed in to change notification settings - Fork 12k
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
Module not found when using type from .d.ts file #4874
Comments
Possibly has to do with this issue. |
Maybe, though I do refer to |
Why not import the .d.ts into the typings.d.ts file instead of into the component? |
Because it's generated and exports interfaces and namespaces, not declares them globally. |
This isn't a CLI issue, but rather a TypeScript/Angular issue. |
They said it's cli issue. Is Angular and CLI 2 separate products? If not, do cooperate. This issue does not happen if using webpack starter, so I don't believe it's issue on Angular or TypeScript side itself. Please reopen this issue and investigate it if you want people to believe that Angular is a serious platform. |
I can confirm this issue, @Draccoz @filipesilva . It does not happen when you change the filename from I just moved a working project from a webpack-starter seed (TypeScript/Angular) to CLI and got this error, so I assume it has something to do with the generated CLI project. I'm using |
Thanks @basst314. I'm afraid though that @filipesilva doesn't care about it at all. |
Hi @filipesilva , As written above, regular typescript imports like Do we have to register our typing-files somewhere in the cli-config to be found during the build? Any help is very much appreciated! |
This might actually be #2034. |
Hey @Draccoz, can you confirm that this does only happen when doing a normal jit build with @filipesilva, #2034 might be related, but this one breaks the build, the other displays a warning and does not break the build. Also the concrete error message is different. Thanks! |
Confirming the above.
|
Can confirm this is still an issue in Angular CLI 1.0.2
|
any news on this? it's pretty annoying! |
+1 |
+1 Any updates on this? |
Does anyone have a workaround for this (aside from using the [edit]: a workaround for anyone following along is to declare the property with an intersection type: export class FooComponent {
@Input() public foo: IFoo; // does not work
@Input() public foo: IFoo & { }; // works
} |
name the files differently. e.g.
`.def.ts`
On 21 Jul 2017 00:44, "Marshall Cottrell" <[email protected]> wrote:
Does anyone have a workaround for this (aside from using the any type on
the input)?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#4874 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACwLMvfmURHRHyCsREdtbWeRjQF4lkzKks5sP9hPgaJpZM4MHWjJ>
.
|
@18steps I'm affraid this is not possible in my case. TypeScript treats *.d.ts files in a special way that it doesn't compile them into the bundle. In my project (non-angular), I use *.d.ts file which is placed outside the root of my project. The reason for that is because the file is shared with another project (angular + angular/cli). When compiling, TypeScript refers to that file with Here's an example how it looks when I use *.d.ts file:
And here's how it looks when I change the *.d.ts to *.def.ts (or anything else):
If you take a look at the /dist folder in the second example you'll notice that the compiler "moved" the root of the application 2 levels up. I was searching for a solution for this behavior in the TS documentation but didn't find anything useful. Maybe someone knows some trick in the tsconfig.json that would solve my problem but this is something different from the bug described in this thread. |
@filipesilva and @hansl can you estimate when there will be time to fix this issue? I see it has been labeled 'priotity urgent' but so far nothing has happened. |
Another workaround similar to marshall007's is to declare it like this:
|
I can also confirm what @PhotoPaul said. This is a serious issue, I hope it can be solved as soon as possible. |
@hansl let's get some kind of resolution please? |
In my case it seems to be failing when it is loading the typescript via webpack (see
I get this myself when I use webpack (the 'Fingerprint2' class name corresponds to a .d.ts file I have under node_modules and typescript's compiler finds it fine): error TS2304: Cannot find name 'Fingerprint2'. it seems like it isn't finding the .d.ts file in the @ngtools/webpack loader when running webpack. |
In my project I'm getting the same error message as Asken. It only happens when using AOT. And I also narrowed it down to using a type imported from a package (with .d.ts) inside a decorator (e.g. The error message itself seems to originate from inside
My setup:import { IMyService } from 'my-interface-package';
import { MyActualService } from 'my-implementation-package';
// IMyService is actually not an interface, but an abstract class, so it can be used for DI.
@NgModule({
providers: [
{ provide: IMyService, useClass: MyActualService }
]
})
export class AppModule {} Planned workaround for now: export const MY_SERVICE_TOKEN = new InjectionToken('IMyService'); @NgModule({
providers: [
{ provide: MY_SERVICE_TOKEN, useClass: MyActualService }
]
})
export class AppModule {}
@Component({
template: '...',
})
export class SomeComponent {
// Using IMyService here for parameter type does not cause an error.
constructor(@Inject(MY_SERVICE_TOKEN) private myService: IMyService) {}
} |
I'm still have this issue as well. In AOT only |
I started getting this today, where yesterday I didn't have it. The only thing I can think of is that between now and then, I upgraded to the following:
from:
I am going to revert, rebuild, and report back. |
Reverting did not help. I'm still going to keep poking around. |
I'm not sure if I'm even experiencing the same issue. However, I pointed my tsconfig aliases for my library projects from their |
@dudewad Can you please provide a reproduction repository we can use to investigate this? It seems there are some metadata emitted from Angular's decorators, and we should be stripping those before we compile in AOT. |
This bug is still happening with version Also (hoping that this can help with the bug resolution), I noticed that if you create two files like:
and try to include in |
Yes, This bug is still happening with version 7.1.4. |
I had the same problem: Files with the ending In my case the problem caused by the option Setting
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
I started this issue on angular/angular issues, but seems to be related to CLI, so just copy-pasting the issue here :).
I'm submitting a ...
Current behavior
When assigning a custom type (like Post, or User) to a decorated property (with either ng decorator like
@Input()
or a custom one), where type is declared ind.ts
file, angular throws an error:This does not happen if:
Array<Post>
) OR.ts
extension instead of.d.ts
Expected behavior
No error should be thrown. property should have given type.
Minimal reproduction of the problem with instructions
ng init
to create a new Angular project.d.ts
file inapp
folder.d.ts
file@Input() prop: MyType
)ng serve
What is the motivation / use case for changing the behavior?
The default workflow in TypeScript suggests keeping declarations and interfaces in
.d.ts
file. Simple Angular components might not use Observables and still accept data from the host. I am actually surprised nobody mentioned and solved it so far as it is pretty severe (it also happens in4.0.0-beta.8
).Please tell us about your environment:
The text was updated successfully, but these errors were encountered: