Typhoon pours 5 inches of rain on Taiwan, heads for Shanghai