如何得到想要的输出? 对于文本文件,当满足以下条件之一时:
例如 输入:
TypeScript ch6 (2/3) Advanced Function Types
Types TypeScript
Totality TSC Flag: noImplicitReturns Advanced Object Types
The keyof operator TSC Flag: keyofStringsOnly The Record Type Mapped Types Built-in mapped types
type Weekday = 'Mon' | 'Tue' | 'Wed'|'Thu'|'Fri'
type Day = Weekday | 'Sat' | 'Sun'
// Error: Function lacks ending return statement and return type does not include 'undefined'.
function getNextDay(w: Weekday): Day {
switch(w) {
case 'Mon': return 'Tue'
}
}
{ }
{
}
{
{
test
}
}
const i = 1
TSC Flag: noImplicitReturns tsconfig"noImplicitReturns": true // Error: Not all code paths return a value.
function isBig(n: number) {
if (n >= 100) {
return true
}
}
Advanced Object Types Type Operators for Object Types
Companion Object Pattern
type APIResponse = {
user: {
userId: string,
friendList: {
count: number,
friends: {
firstName: string,
lastName: string
}[]
}
}
}
function getAPIResponse(): Promise<APIResponse> {
// ...
}
const response = await getAPIResponse()
renderFriendList(response.user.friendList)
friendListtypehint any FriendList
输出:
//TypeScript ch6 (2/3) Advanced Function Types
// Types TypeScript
// Totality TSC Flag: noImplicitReturns Advanced Object Types
// The keyof operator TSC Flag: keyofStringsOnly The Record Type Mapped Types Built-in mapped types
type Weekday = 'Mon' | 'Tue' | 'Wed'|'Thu'|'Fri'
type Day = Weekday | 'Sat' | 'Sun'
// Error: Function lacks ending return statement and return type does not include 'undefined'.
function getNextDay(w: Weekday): Day {
switch(w) {
case 'Mon': return 'Tue'
}
}
{ }
{
}
{
{
test
}
}
const i = 1
// TSC Flag: noImplicitReturns tsconfig"noImplicitReturns": true // Error: Not all code paths return a value.
function isBig(n: number) {
if (n >= 100) {
return true
}
}
// Advanced Object Types Type Operators for Object Types
// Companion Object Pattern
type APIResponse = {
user: {
userId: string,
friendList: {
count: number,
friends: {
firstName: string,
lastName: string
}[]
}
}
}
function getAPIResponse(): Promise<APIResponse> {
// ...
}
const response = await getAPIResponse()
renderFriendList(response.user.friendList)
// friendListtypehint any FriendList
我试过这个脚本,它没有正确处理“以“{”开头并以“}”作为一行的第一个字符的多行”:
awk '{
if ($1 ~ /type/ || $1 ~ /const/ || $0 ~ /\(.*)/ || $0 ~ /{.*}/ || $0 ~ /\/\//)
print $0;
else
if ($0 !~ /}/)
print "//", $0;
else
print $0;
}' input