Skip to content

An option to enforce emitting order #12881

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

Closed
rtpg opened this issue Dec 13, 2016 · 5 comments
Closed

An option to enforce emitting order #12881

rtpg opened this issue Dec 13, 2016 · 5 comments
Labels
Duplicate An existing issue was already created

Comments

@rtpg
Copy link

rtpg commented Dec 13, 2016

I know I can control the order of files via the ordering provided in my config (either in files or include). But since things like types can change ordering so that even if we have files:['a.ts', 'b.ts'], then the resulting output will have b.ts's compiled output first (see here)

Would it be possible to add a compiler flag so that we can enforce that a.ts doesn't pull in b.ts? To enforce the ordering provided in files or include? I tried looking into doing this myself but this project's quite big. Something like a compiler error when trying to pull in a file that is "after" the current file in the include order.

Ideally, being able to make it so that if I have:
include: [ "library/*", "core/*", "ui/*" ]

then files within library/* could depend on each other but not on things in core/* , and core/* could not depend on anything in ui/* (but could depend on things in core/* or lib/*). This would already help to solve many of my ordering-related headaches which mean I cannot use things like the import statement safely.

@RyanCavanaugh RyanCavanaugh added the Needs More Info The issue still hasn't been fully clarified label Dec 13, 2016
@RyanCavanaugh
Copy link
Member

The only thing you need to do to get this behavior is not have /// <reference directives in your files. If you have a tsconfig listing your files, there's no reason to have those directives, so that should be a straightforward policy you could enforce with TSLint (or a simple commandline script).

I'm also a little confused on import - if you're using import (as in modules), there's no "order" per se.

@mhegazy
Copy link
Contributor

mhegazy commented Dec 13, 2016

Please note that we have a bug where the order of files listed in include is not honored at the moment. see #11461. this should be fixed in upcoming releases.

@rtpg
Copy link
Author

rtpg commented Dec 14, 2016

This might be a case of the include issue, though my issue went away once I moved around some type definitions, so I feel like "something" is happening.

In my case I had a.d.ts, b.ts , and c.ts. I wanted the output to be in the sam order.

b.ts used types from a.d.ts which had a type from c.ts, so c.ts came out first, despite the fact that the include order was something like include: ['a.d.ts', 'b.ts', 'c.ts']. I have no reference paths in my code.

Once I moved c.ts's interface definitions from c.ts to a.d.ts, the code started coming out in the right order.

Unfortunately I am unable to get this to happen for me in a minimal example, making me think something else is also going on. But the reality is that the output order was not the same as the import order in include. This could be a duplicate of #11461

@mhegazy
Copy link
Contributor

mhegazy commented Dec 14, 2016

use tsc --listFiles to see what order the compiler sees the input. you can see --traceResolution to know what files "imported" your file.

@rtpg
Copy link
Author

rtpg commented Dec 14, 2016

I do see the behaviour of #11461 with that command. I don't seem to be able to replicate my "fix" for the output, though. Might have been a hallucination on my part.

If the include order is fixed, that will probably solve the reasoning behind this issue as well.

@mhegazy mhegazy added Duplicate An existing issue was already created and removed Needs More Info The issue still hasn't been fully clarified labels Dec 14, 2016
@mhegazy mhegazy closed this as completed Apr 19, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants