ember-cli-typescript
ember-cli-typescript copied to clipboard
`SafeString` is "private"
Which package(s) does this problem pertain to?
- [ ] @types/ember
- [ ] @types/ember__string
- [ ] @types/ember__polyfills
- [ ] @types/ember__object
- [ ] @types/ember__utils
- [ ] @types/ember__array
- [ ] @types/ember__engine
- [ ] @types/ember__debug
- [ ] @types/ember__runloop
- [ ] @types/ember__error
- [ ] @types/ember__controller
- [ ] @types/ember__component
- [ ] @types/ember__routing
- [ ] @types/ember__application
- [x] @types/ember__template
- [ ] @types/ember__test
- [ ] @types/ember__test-helpers
- [ ] @types/ember__service
- [ ] @types/ember-data
- [ ] @types/rsvp
- [ ] Other
- [ ] I don't know
What are instructions we can follow to reproduce the issue?
There is no public re-export of SafeString, which is the return type of htmlSafe. If you have a function or getter that returns the result of calling htmlSafe, the return type is "unnamable". There are workarounds, like RetrunType<typeof htmlSafe>, but 😬
Reproduction Case
import { htmlSafe } from '@ember/tempalte';
export function myFunc(str: string): ??? {
return htmlSafe(str);
}
Now about that bug. What did you expect to see?
Something I can import to fill in the ???.
What happened instead?
There is nothing I can import to fill in the ???.
(By the way, the issue templates are missing @types/ember__template)
I just hit this today as well, thanks for posting a workaround!
The TS docs are also missing @types/ember__template
https://ember-cli-typescript.com/docs
I actually use import { SafeString } from 'handlebars'; and that seems to work. But I also use import { htmlSafe } from '@ember/string'; which is different from import { htmlSafe } from '@ember/tempalte';... in some way? Not sure why that function is exported from two different packages. Is it different in some way?
Thanks for reporting. FWIW, the problem here is the same as the problem with Transition (and which technically should exist for RouterService as well, but we don't have alignment in what we did there): there's no defined public API for where to import these type-only imports, and we've been loathe to add imports that don't exist in Ember's public API b/c then we have a SemVer coordination problem. I expect to address this with forthcoming RFCs around Ember and TS support, because it's a key concern for many framework APIs.
I think SafeString should be public, and we missed it in the work on Ember RFC 0830, but it should be straightforward to implement. Insofar as folks want this to happen, please open an issue on Ember itself, as this repo is no longer the source of truth for (bug reports about) types for Ember—Ember is!