You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Any file name with .d. in it ending with .ts is a declaration file in 5.0.2 even without --allowArbitraryExtensions #53319
Right now the only way I see to set if a file type is ambient is through the extension. Maybe the API needs a better way for consumers to tell it "this is a declaration file"? Maybe on CreateSourceFileOptions? Then perhaps the code that does the arbitrary extension resolution could mark the declaration file that matches the arbitrary extension as ambient and the code here could be reverted.
I think the logic got a little twisted up here, it's intentional to not just look for exactly .d.ts since .d.cts and .d.mts are also valid declaration filenames. Just needs a tweak.
Ryan Cavanaugh (@RyanCavanaugh) what needs to be tweaked here? I would help fix this, but I don't know what should change to fix it because maybe this is intended behaviour now.
To summarize the issue, the --allowArbitraryExtensions added support for things like .d.css.ts to be marked as declaration files. The issue is that this is done unconditionally even without --allowArbitraryExtensions when calling ts.createSourceFile.
I feel like a fix would be to have a way for the createSourceFile API to specify if something is a declaration file?
Right now the only way I see to set if a file type is ambient is through the extension. Maybe the API needs a better way for consumers to tell it "this is a declaration file"? Maybe on CreateSourceFileOptions? Then perhaps the code that does the arbitrary extension resolution could mark the declaration file that matches the arbitrary extension as ambient and the code here could be reverted.
Maybe an issue though is in the language server you probably want a way to tell if a file is a declaration file solely based on the file path I think? Maybe that could be figured out if a corresponding .ext file is there... so for example if file.ext is there then maybe file.d.ext.ts will be marked as a declaration file (seems maybe slightly unfortunate this is .d.ext.ts and not .ext.d.ts even with the reasoning in the blog post). Edit: or I guess it could just resolve .d.*.ts as a declaration file only when allowArbitraryExtensions is set in the tsconfig... I'm not sure at all though because I'm not that familiar with the ts language server
I think this was meant to be behind the --allowArbitraryExtensions flag?
Nope! These are always recognized as declaration files now; the flag only controls weather we issue an error on their use to resolve an import in .ts source files (which we know is technically a break, if very unlikely, but that's what the moral cover of 5.0 is for). They're also always valid from declaration file to declaration file, this way they can be used to describe things portably on DT. Generally, the less flags actually affect resolution, the better.
Edit: or I guess it could just resolve .d.*.ts as a declaration file only when allowArbitraryExtensions is set in the tsconfig... I'm not sure at all though because I'm not that familiar with the ts language server
WIldcard directory includes (like the compiler without any configuration) suck in all files ending in .ts, which happens to include all declaration files (since they also end in .ts), and then just filters out those declaration files whose original source files are also present.
I feel like a fix would be to have a way for the createSourceFile API to specify if something is a declaration file?
Nah, I don't think we'd like this. We like being able to map from declaration file path back to original source file path, and if you can mark arbitrary files as "declaration", we lose that capability.
Activity
RyanCavanaugh commentedon Mar 17, 2023
I think the logic got a little twisted up here, it's intentional to not just look for exactly
.d.tssince.d.ctsand.d.mtsare also valid declaration filenames. Just needs a tweak.dsherret commentedon Mar 17, 2023
Ryan Cavanaugh (@RyanCavanaugh) what needs to be tweaked here? I would help fix this, but I don't know what should change to fix it because maybe this is intended behaviour now.
To summarize the issue, the
--allowArbitraryExtensionsadded support for things like.d.css.tsto be marked as declaration files. The issue is that this is done unconditionally even without--allowArbitraryExtensionswhen callingts.createSourceFile.I feel like a fix would be to have a way for the
createSourceFileAPI to specify if something is a declaration file?Maybe an issue though is in the language server you probably want a way to tell if a file is a declaration file solely based on the file path I think? Maybe that could be figured out if a corresponding
.extfile is there... so for example iffile.extis there then maybefile.d.ext.tswill be marked as a declaration file (seems maybe slightly unfortunate this is.d.ext.tsand not.ext.d.tseven with the reasoning in the blog post). Edit: or I guess it could just resolve.d.*.tsas a declaration file only whenallowArbitraryExtensionsis set in the tsconfig... I'm not sure at all though because I'm not that familiar with the ts language serverRyanCavanaugh commentedon Mar 17, 2023
Wesley Wigham (@weswigham) can you weigh in?
weswigham commentedon Mar 17, 2023
Nope! These are always recognized as declaration files now; the flag only controls weather we issue an error on their use to resolve an import in
.tssource files (which we know is technically a break, if very unlikely, but that's what the moral cover of 5.0 is for). They're also always valid from declaration file to declaration file, this way they can be used to describe things portably on DT. Generally, the less flags actually affect resolution, the better.WIldcard directory includes (like the compiler without any configuration) suck in all files ending in
.ts, which happens to include all declaration files (since they also end in.ts), and then just filters out those declaration files whose original source files are also present.weswigham commentedon Mar 17, 2023
Nah, I don't think we'd like this. We like being able to map from declaration file path back to original source file path, and if you can mark arbitrary files as "declaration", we lose that capability.
dsherret commentedon Mar 17, 2023
That's fair. I think we can close this issue then?
weswigham commentedon Mar 17, 2023
Yeah, this is working as intended.
dsherret commentedon Mar 17, 2023
Btw, thanks for the clarification! I will just make a few small changes on our side and this is not a big deal.