Skip to content
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

Required triple-slash types reference no longer generated in TS 5.5 #58985

Closed
justinfagnani opened this issue Jun 24, 2024 · 2 comments
Closed

Comments

@justinfagnani
Copy link

πŸ”Ž Search Terms

triple slash reference types omitted

#57681

πŸ•— Version & Regression Information

  • This changed between versions 5.3.3 and 5.5.0

⏯ Playground Link

lit/lit#4682

πŸ’» Code

I couldn't make a playground that shows the problem, because it requires a dependency.

package.json:

  "dependencies": {
    "@types/trusted-types": "^2.0.2"
  },

tsconfig.json

{
  "compilerOptions": {
    "types": ["trusted-types"]
  },
}

index.ts (part of package dep)

export const foo = (html: string | TrustedHTML) => Foo;

app.js (part of package app, depends on the package dep):

import {foo} from 'dep';

πŸ™ Actual behavior

When compiling the package app, the compile error is that in dep/index.d.ts, the type TrustedHTML isn't found.

πŸ™‚ Expected behavior

No compile errors.

Additional information about the issue

The problem seems to be that a triple-slash directive used to be emitted and now isn't:

/// <reference types="trusted-types" />

This is might due to #57681 however this isn't about not preserving a reference, since the reference used to be generated by the compiler. This is about the compiler newly not generating a required reference at all.

Changing the library code to:
index.ts (as part of package dep)

/// <reference types="trusted-types" preserve="true" />
export const foo = (html: string | TrustedHTML) => Foo;

fixes the problem, but this seems like a bug because before the compiler was correctly inferring that the reference was required for the declaration file, and now it's not.

@IllusionMH
Copy link
Contributor

It's intentional for user-written reference directives as well and mentioned in https://devblogs.microsoft.com/typescript/announcing-typescript-5-5/#simplified-reference-directive-declaration-emit

@justinfagnani
Copy link
Author

Thanks. I looked for issues, but missed that in the release notes πŸ€¦β€β™‚οΈ

Reference directives are no longer synthesized

Since this is intentional, I'll close the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants