string String Type

Last updated: 2026-10-22

string String Type

string represents text. Use it for names, messages, IDs — any data that lives as characters. It is the most common type in everyday code.

GroupBasic Types
KindType
Strict modeNot required

ℹ️ Info The editor transpiles TypeScript to JavaScript and runs it (no type checking); see each example's Output for type-check results.

📝 Syntax

let title: string = "TypeScript Manual";
let greeting = `Hello, ${title}`; // template literals embed variables

⚙️ Parameters

`${expr}`Template literal: backtick string with expressions embedded inside ${}

Returns:None — string is a basic type annotation and produces no runtime code.

▶ Example

Edit the code below and click Try it to see the transpiled result:

Output:

Item TS-1001 x3
15 ITEM TS-1001 X3

(Runtime output after transpilation; assigning a number to label makes .toUpperCase a compile error)

💡 Notes

ℹ️ Info Always annotate with lowercase string, never the wrapper type String — they differ: String also allows objects like new String().
💡 Tip Prefer template literals over + concatenation — clearer, and they support multi-line text.
⚠️ Note string only guarantees "is text", not the format; validating emails or phone numbers requires runtime regex — types cannot help there.
More cases coming soon.

📚 Related tutorials

❓ FAQ

Q How do string and String differ?
A string is the primitive type; String is the wrapper object type (also accepts new String() objects). Always annotate with lowercase string.
Q Template literals vs + concatenation?
A Same result, but templates read better, span multiple lines, and ${} accepts any expression. Prefer them for longer strings.
Q How do literal unions like "a" | "b" relate to string?
A string is the superset; a literal union is a subset. A string is not assignable to "a" | "b", but the reverse works. Use literal unions to restrict values (see literal-types).
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏