Skip to content

[Suggestion] HTML string type for IDEs #4856

Closed
@aciccarello

Description

@aciccarello

Motivation

ES6 Template strings make it much easier to put blocks of HTML code inline with JavaScript. This can be leveraged in frameworks like Angular. One disadvantage to this though, is that IDEs don't know that the string block should be formatted as HTML so there is no syntax highlighting.

@Component({ selector: 'angular-demo' })
@View({
  template: `<h3>My Template</h3>
             <p>I can put blocks of HTML here.</p>
             <p>Unfortunately, there is no syntax highlighting.</p>`
})
class Demo{ }

Proposal

I propose a simple HTMLString type that is simply an alias for string but can signal to text editors that the string should be styled as HTML and can use HTML completion. This should be implemented in lib.d.ts to standardize the use of the type.

/**
 * Alias for the string type used to denote the string should be shown with
 * HTML syntax highlighting
 */
type HTMLString = string;

Strengths:

  • Simple to implement
  • No breaking changes
  • IDE support is optional

Weaknesses:

  • Requires IDEs to be interested in implementing

Metadata

Metadata

Assignees

No one assigned

    Labels

    DeclinedThe issue was declined as something which matches the TypeScript visionOut of ScopeThis idea sits outside of the TypeScript language design constraintsSuggestionAn idea for TypeScriptToo ComplexAn issue which adding support for may be too complex for the value it adds

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions